$response->message = 'Not found'; $response->json($response); } if (!$model->iconDelete(array('id' => $api->getInputVal('id'), 'user_id' => $user->id))) { $response->status = 500; $response->message = 'Unable to delete the icon'; $response->json($response); } $path = 'storage/icons/'; if (is_file($path . $icon->file)) { unlink($path . $icon->file); } if (is_file($path . $icon->icon)) { unlink($path . $icon->icon); } Ut::cleanDirectory($path . $icon->name); $response->json($response); } elseif ($route->match('iconupload', 1)) { $api->setInputs(array('name' => $route->getParam(0))); $name = Ut::toSlug(strtok($_FILES['file']['name'], '.')); // Check if skin name and uploaded name are equal if ($api->getInputVal('name') !== $name) { $response->status = 500; $response->message = 'The uploaded file must be named: ' . $api->getInputVal('name') . '!!! Your file name is: ' . $name; $response->json($response); } // Check if model exists $icon = $model->iconFind(array('user_id' => $user->id, 'name' => $api->getInputVal('name'))); if (!$icon) { $response->status = 404; $response->message = 'Icon not found';
/** * Delete a file or recursively delete a directory * * @param string $dir Path to file or directory * @return void */ public static function cleanDirectory($dir) { // var_dump($dir); // return; if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir . "/" . $object) === "dir") { Ut::cleanDirectory($dir . "/" . $object); } else { unlink($dir . "/" . $object); } } } reset($objects); rmdir($dir); } }
/** * Pack to a tar.gz archive * * @param string $path * @param string $target * return bool */ public function uploadSkin($uploader, $skin_path, $skin_path_temp) { //file is the filebrowse element name if (!$uploader->uploadFile('file')) { $this->setErrors($uploader->getMessage()); return false; } //get uploaded file name, renames on upload// $file = $uploader->getUploadName(); $file_name = strtok($file, '.'); $file_extension = $uploader->getExtension($file); // Filename default is not allowed if ($file_name === 'default') { if (is_file($skin_path . $file)) { unlink($skin_path . $file); } $this->setErrors('File name "' . $file_name . '" is not allowed. Please select a different name and try again.'); return false; } do { if ($file_extension !== 'zip') { break; } // Unpack zip file if (!$this->unpackZip($skin_path . $file, $skin_path_temp . $file_name)) { $this->setErrors('Unable to unpack file "' . $file . '"'); return false; } // Unlink uploaded Zip file unlink($skin_path . $file); if (is_file($skin_path . $file_name . '.tar.gz')) { unlink($skin_path . $file_name . '.tar.gz'); } // Create a tar.gz archive if (!$this->packTargz($skin_path_temp . $file_name, $skin_path . $file_name)) { $this->setErrors('Unable to create tar.gz from file "' . $file . '"'); return false; } // Clean temp directory Ut::cleanDirectory($skin_path_temp . $file_name); $file = $file_name . '.tar.gz'; } while (false); return $file; }