public function index() { define('DEBUG', true); // an array of file extensions to accept $accepted_extensions = array("png", "jpg", "gif"); // http://your-web-site.domain/base/url $base_url = url::base() . Kohana::config('upload.relative_directory', TRUE) . "jwysiwyg"; // the root path of the upload directory on the server $uploads_dir = Kohana::config('upload.directory', TRUE) . "jwysiwyg"; // the root path that the files are available from the webserver $uploads_access_dir = Kohana::config('upload.directory', TRUE) . "jwysiwyg"; if (!file_exists($uploads_access_dir)) { mkdir($uploads_access_dir, 0775); } if (DEBUG) { if (!file_exists($uploads_access_dir)) { $error = 'Folder "' . $uploads_access_dir . '" doesn\'t exists.'; header('Content-type: text/html; charset=UTF-8'); print '{"error":"config.php: ' . htmlentities($error) . '","success":false}'; exit; } } $capabilities = array("move" => false, "rename" => true, "remove" => true, "mkdir" => false, "upload" => true); if (extension_loaded('mbstring')) { mb_internal_encoding('UTF-8'); mb_regex_encoding('UTF-8'); } require_once Kohana::find_file('libraries/jwysiwyg', 'common', TRUE); require_once Kohana::find_file('libraries/jwysiwyg', 'handlers', TRUE); ResponseRouter::getInstance()->run(); }
if (rename($root . $dir . $file, $root . $newPath)) { return array("success" => true, "data" => "File already exists "); } else { return array("success" => false, "error" => "Couldn't move file."); } } } ResponseRouter::getInstance()->setHandler("move", new MoveHandler()); class UploadHandler extends ResponseHandler { public function getResponse($router) { $dir = $router->normalizeDir($_POST['dir']); $root = $router->getConfig()->getRootDir(); $dst = $root . $dir . $_POST['newName']; if (file_exists($dst)) { $message = array('success' => false, 'error' => 'File already exists.'); echo $message['error']; } if (!is_uploaded_file($_FILES['handle']['tmp_name'])) { return array('success' => false, 'error' => 'Couldn\'t upload file.'); } if (!move_uploaded_file($_FILES['handle']['tmp_name'], $dst)) { return array('success' => false, 'error' => 'Couldn\'t upload file.'); } $message = array('success' => true, 'data' => 'File upload successful.'); echo $message['data']; } } ResponseRouter::getInstance()->setHandler("upload", new UploadHandler());
public static function getInstance() { if (!self::$instance instanceof ResponseRouter) { self::$instance = new ResponseRouter(); } return self::$instance; }
define('DEBUG', true); if (DEBUG) { error_reporting(E_ALL | E_NOTICE | E_STRICT); ini_set('display_errors', 'On'); ini_set('display_startup_errors', 'On'); $error_log_file = dirname(__FILE__) . '/errors.log'; // Test if error log is writable. $error = ''; if (file_exists($error_log_file) && !is_writable($error_log_file)) { $error = 'Make file "' . $error_log_file . '" writable or set debug to false.'; } else { if (!file_exists($error_log_file) && !is_writable(dirname($error_log_file))) { $error = 'Make dir "' . dirname($error_log_file) . '" writable or set debug to false.'; } } if ($error) { header('Content-type: text/html; charset=UTF-8'); print '{"error":"file-manager.php: ' . htmlentities($error) . '","success":false}'; exit; } ini_set('error_log', $error_log_file); ini_set('log_errors', 'On'); } if (extension_loaded('mbstring')) { mb_internal_encoding('UTF-8'); mb_regex_encoding('UTF-8'); } require_once 'common.php'; require_once 'handlers.php'; ResponseRouter::getInstance()->run();