public function uploader() { error_reporting(0); JLoader::register('PluploadHandler', JPATH_SITE . '/components/com_judownload/helpers/pluploadhandler.php'); $targetDir = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/") . "tmp"; $cleanupTargetDir = true; $maxFileAge = 5 * 3600; $this->cleanup($targetDir, $maxFileAge); if (!JFolder::exists($targetDir)) { JFolder::create($targetDir); $indexHtml = $targetDir . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($indexHtml, $buffer); } if (!is_writable($targetDir)) { $targetDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "plupload"; if (!file_exists($targetDir)) { @mkdir($targetDir); } } PluploadHandler::no_cache_headers(); PluploadHandler::cors_headers(); if (!PluploadHandler::handle(array('target_dir' => $targetDir, 'cleanup' => $cleanupTargetDir, 'max_file_age' => $maxFileAge, 'cb_check_file' => array(__CLASS__, 'canUpload')))) { die(json_encode(array('OK' => 0, 'error' => array('code' => PluploadHandler::get_error_code(), 'message' => PluploadHandler::get_error_message())))); } else { die(json_encode(array('OK' => 1))); } }
function upload_images() { global $user, $MSG, $system; if (!$user->logged_in) { // imitate code execution die(json_encode(array('OK' => 0, 'error' => array('code' => '202', 'message' => $MSG['login_required_text'])))); } else { require_once PACKAGE_PATH . 'PluploadHandler.php'; $uploader = new PluploadHandler(); $uploader->no_cache_headers(); $uploader->cors_headers(); $targetDir = UPLOAD_PATH . session_id(); if (!$uploader->handle(array('target_dir' => $targetDir, 'allow_extensions' => 'jpg,jpeg,png,gif'))) { die(json_encode(array('OK' => 0, 'error' => array('code' => $uploader->get_error_code(), 'message' => $uploader->get_error_message())))); } else { //upload was good $conf = $uploader->get_conf(); $fileName = $conf['file_name']; // resize picture $uploader->resizeThumbnailImage($targetDir . '/' . $fileName, $system->SETTINGS['gallery_max_width_height']); $final_file_name = strtolower($fileName); if (!in_array($final_file_name, $_SESSION['UPLOADED_PICTURES'])) { array_push($_SESSION['UPLOADED_PICTURES'], $final_file_name); if (count($_SESSION['UPLOADED_PICTURES']) == 1) { $_SESSION['SELL_pict_url_temp'] = $_SESSION['SELL_pict_url'] = $final_file_name; } } die(json_encode(array('OK' => 1))); } } }
function upload_images() { global $user, $MSG; if (!$user->logged_in) { // imitate code execution die(json_encode(array('OK' => 0, 'error' => array('code' => '202', 'message' => $MSG['login_required_text'])))); } else { global $main_path, $upload_path, $include_path; require_once $include_path . "PluploadHandler.php"; $uploader = new PluploadHandler(); $uploader->no_cache_headers(); $uploader->cors_headers(); $targetDir = $upload_path . session_id(); if (!$uploader->handle(array('target_dir' => $targetDir, 'allow_extensions' => 'jpg,jpeg,png,gif'))) { die(json_encode(array('OK' => 0, 'error' => array('code' => $uploader->get_error_code(), 'message' => $uploader->get_error_message())))); } else { //upload was good $conf = $uploader->get_conf(); $fileName = $conf['file_name']; if (!in_array($fileName, $_SESSION['UPLOADED_PICTURES'])) { $final_file_name = strtolower($fileName); array_push($_SESSION['UPLOADED_PICTURES'], $final_file_name); if (count($_SESSION['UPLOADED_PICTURES']) == 1) { $_SESSION['SELL_pict_url_temp'] = $_SESSION['SELL_pict_url'] = $final_file_name; } } die(json_encode(array('OK' => 1))); } } }
/** * Handle ajax chunked file uploads. */ function humcore_upload_handler() { global $fedora_api; require_once dirname(__FILE__) . '/PluploadHandler.php'; PluploadHandler::no_cache_headers(); PluploadHandler::cors_headers(); $upload_status = PluploadHandler::handle(array('target_dir' => $fedora_api->tempDir . '/', 'allow_extensions' => 'csv,doc,docx,f4v,flv,gif,gz,htm,html,jpeg,jpg,mov,mp3,mp4,odp,ods,odt,ogg,pdf,png,ppt,pptx,pps,psd,rdf,rtf,sxc,sxi,sxw,tar,tiff,txt,tsv,wav,wpd,xls,xlsx,xml,zip')); if (!$upload_status) { die(json_encode(array('OK' => 0, 'error' => array('code' => PluploadHandler::get_error_code(), 'message' => PluploadHandler::get_error_message())))); } else { die(json_encode(array('OK' => 1))); } }
public function upload() { if (!$_REQUEST['uid']) { echo Response::json(LACK, array(tip('用户ID不能为空'))); exit; } $_REQUEST['name'] = self::filterName(rawurldecode(self::trimSpace($_REQUEST['name']))); if (!$_REQUEST['name']) { echo Response::json(LACK, array(tip('文件名不能为空'))); exit; } if (!$_REQUEST['type']) { if (!file_exists(DATA_DIR)) { $res = mkdir(DATA_DIR, 0777, true); if (!$res) { echo Response::json(FAIL, array(tip('存储目录创建失败'))); exit; } } } if (!file_exists(UP_DIR)) { $res = mkdir(UP_DIR, 0777, true); if (!$res) { echo Response::json(FAIL, array(tip('存储目录创建失败'))); exit; } } include LIB_PATH . 'plupload' . DS . 'PluploadHandler.php'; PluploadHandler::no_cache_headers(); PluploadHandler::cors_headers(); if (!PluploadHandler::handle(array('target_dir' => UP_DIR))) { echo Response::json(FAIL, array(tip('上传失败'))); exit; } else { echo Response::json(SUCC, array(tip('上传成功'))); } }
static function handle($conf = array()) { global $_FILES; // 5 minutes execution time @set_time_limit(5 * 60); self::$_error = null; // start fresh $conf = self::$conf = array_merge(array('file_data_name' => 'file', 'tmp_dir' => ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload", 'target_dir' => false, 'cleanup' => true, 'max_file_age' => 5 * 3600, 'chunk' => isset($_REQUEST['chunk']) ? intval($_REQUEST['chunk']) : 0, 'chunks' => isset($_REQUEST['chunks']) ? intval($_REQUEST['chunks']) : 0, 'file_name' => isset($_REQUEST['name']) ? $_REQUEST['name'] : false, 'allow_extensions' => false, 'delay' => 0, 'cb_sanitize_file_name' => array(__CLASS__, 'sanitize_file_name'), 'cb_check_file' => false), $conf); try { if (!$conf['file_name']) { if (!empty($_FILES)) { $conf['file_name'] = $_FILES[$conf['file_data_name']]['name']; } else { throw new Exception('', PLUPLOAD_INPUT_ERR); } } // Cleanup outdated temp files and folders if ($conf['cleanup']) { self::cleanup(); } // Fake network congestion if ($conf['delay']) { usleep($conf['delay']); } if (is_callable($conf['cb_sanitize_file_name'])) { $file_name = call_user_func($conf['cb_sanitize_file_name'], $conf['file_name']); } else { $file_name = $conf['file_name']; } // Check if file type is allowed if ($conf['allow_extensions']) { if (is_string($conf['allow_extensions'])) { $conf['allow_extensions'] = preg_split('{\\s*,\\s*}', $conf['allow_extensions']); } if (!in_array(strtolower(pathinfo($file_name, PATHINFO_EXTENSION)), $conf['allow_extensions'])) { throw new Exception('', PLUPLOAD_TYPE_ERR); } /* TODO: Fix this WHY THIS NO WORK $mime_types = $conf['allow_extensions']; array_walk($mime_types, function(&$value, $key) { $value = 'image/' . $value; }); // check mime type $finfo = finfo_open(FILEINFO_MIME_TYPE); if (!in_array(finfo_file($finfo, $_FILES[$conf['file_data_name']]['tmp_name'])) { throw new Exception('', PLUPLOAD_TYPE_ERR); } finfo_close($finfo);*/ } $file_path = rtrim($conf['target_dir'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file_name; $tmp_path = $file_path . ".part"; // Write file or chunk to appropriate temp location if ($conf['chunks']) { self::write_file_to("{$file_path}.dir.part" . DIRECTORY_SEPARATOR . $conf['chunk']); // Check if all chunks already uploaded if ($conf['chunk'] == $conf['chunks'] - 1) { self::write_chunks_to_file("{$file_path}.dir.part", $tmp_path); } } else { self::write_file_to($tmp_path); } // Upload complete write a temp file to the final destination if (!$conf['chunks'] || $conf['chunk'] == $conf['chunks'] - 1) { if (is_callable($conf['cb_check_file']) && !call_user_func($conf['cb_check_file'], $tmp_path)) { @unlink($tmp_path); throw new Exception('', PLUPLOAD_SECURITY_ERR); } $final_file_path = strtolower($file_path); rename($tmp_path, strtolower($final_file_path)); return array('name' => strtolower($file_name), 'path' => $final_file_path, 'size' => filesize($final_file_path)); } // ok so far return true; } catch (Exception $ex) { self::$_error = $ex->getCode(); return false; } }
<?php require_once "PluploadHandler.php"; PluploadHandler::no_cache_headers(); PluploadHandler::cors_headers(); if (!PluploadHandler::handle(array('target_dir' => 'uploads/', 'allow_extensions' => 'jpg,jpeg,png'))) { die(json_encode(array('OK' => 0, 'error' => array('code' => PluploadHandler::get_error_code(), 'message' => PluploadHandler::get_error_message())))); } else { die(json_encode(array('OK' => 1))); }
/** * */ static function handle($conf = array()) { // 5 minutes execution time @set_time_limit(5 * 60); $conf = self::$conf = array_merge(array('file_data_name' => 'file', 'tmp_dir' => ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload", 'target_dir' => false, 'cleanup' => true, 'max_file_age' => 5 * 3600, 'chunk' => isset($_REQUEST['chunk']) ? intval($_REQUEST['chunk']) : 0, 'chunks' => isset($_REQUEST['chunks']) ? intval($_REQUEST['chunks']) : 0, 'file_name' => isset($_REQUEST['name']) ? $_REQUEST['name'] : uniqid('file_'), 'allow_extensions' => false, 'delay' => 0, 'cb_sanitize_file_name' => array(__CLASS__, 'sanitize_file_name'), 'cb_check_file' => false), $conf); self::$_error = null; // start fresh try { // Cleanup outdated temp files and folders if ($conf['cleanup']) { self::cleanup(); } // Fake network congestion if ($conf['delay']) { usleep($conf['delay']); } if (is_callable($conf['cb_sanitize_file_name'])) { $file_name = call_user_func($conf['cb_sanitize_file_name'], $conf['file_name']); } $file_extension = strtolower(pathinfo($file_name, PATHINFO_EXTENSION)); // Check if file type is allowed if ($conf['allow_extensions']) { if (is_string($conf['allow_extensions'])) { $conf['allow_extensions'] = preg_split('{\\s*,\\s*}', $conf['allow_extensions']); } if (!in_array($file_extension, $conf['allow_extensions'])) { throw new Exception('', PLUPLOAD_TYPE_ERR); } } $file_path = rtrim($conf['target_dir'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file_name; $tmp_path = $file_path . ".part"; // Write file or chunk to appropriate temp location if ($conf['chunks']) { self::write_file_to("{$file_path}.dir.part" . DIRECTORY_SEPARATOR . $conf['chunk']); // Check if all chunks already uploaded if ($conf['chunk'] == $conf['chunks'] - 1) { self::write_chunks_to_file("{$file_path}.dir.part", $tmp_path); } } else { self::write_file_to($tmp_path); } // Upload complete write a temp file to the final destination if (!$conf['chunks'] || $conf['chunk'] == $conf['chunks'] - 1) { rename($tmp_path, $file_path); if (is_callable($conf['cb_check_file']) && !call_user_func($conf['cb_check_file'], $file_path)) { @unlink($file_path); throw new Exception('', PLUPLOAD_SECURITY_ERR); } } } catch (Exception $ex) { self::$_error = $ex->getCode(); return false; } return $file_path; }
if (!file_exists($targetDirBlankFile)) { fopen($targetDirBlankFile, "w"); } $configArray = array( 'target_dir' => $targetDir, 'allow_extensions' => 'txt', 'file_name' => $fileName ); if (!PluploadHandler::handle($configArray)) { die(json_encode(array( 'OK' => 0, 'error' => array( 'code' => PluploadHandler::get_error_code(), 'message' => PluploadHandler::get_error_message() ) ))); } else { // system calls to execute c program for batch processing $commandToExecute = C_EXECUTABLE_NAME . " ". "'" . realpath($targetDir) . "/" .$fileName . "'" . " ". "'" . $emailId . "'"; //echo $commandToExecute; //exit(); system($commandToExecute); }
function upload($filepath = NULL) { $data = $this->input->post(); if (empty($data)) { crud_error("Error: Empty Data !"); } $this->load->library('Plupload'); $oPlupload = new PluploadHandler(); $oPlupload->no_cache_headers(); $oPlupload->cors_headers(); $config['target_dir'] = empty($filepath) ? "./tmp/" : $filepath; $config['allow_extensions'] = 'jpg,jpeg,png'; if (!$oPlupload->handle($config)) { crud_error($oPlupload->get_error_code() . ": " . $oPlupload->get_error_message()); } crud_success(array('OK' => 1)); }
static function handle($conf = array()) { @set_time_limit(5 * 60); self::$_error = null; $conf = self::$conf = array_merge(array( 'file_data_name' => 'file', 'tmp_dir' => ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload", 'target_dir' => false, 'cleanup' => true, 'max_file_age' => 5 * 3600, 'chunk' => isset($_REQUEST['chunk']) ? intval($_REQUEST['chunk']) : 0, 'chunks' => isset($_REQUEST['chunks']) ? intval($_REQUEST['chunks']) : 0, 'file_name' => isset($_REQUEST['name']) ? $_REQUEST['name'] : false, 'allow_extensions' => false, 'delay' => 0, 'cb_sanitize_file_name' => array(__CLASS__, 'sanitize_file_name'), 'cb_check_file' => false, ), $conf); try { if (!$conf['file_name']) { if (!empty($_FILES)) { $conf['file_name'] = $_FILES[$conf['file_data_name']]['name']; } else { throw new Exception('', PLUPLOAD_INPUT_ERR); } } if ($conf['cleanup']) { self::cleanup(); } if ($conf['delay']) { usleep($conf['delay']); } if (is_callable($conf['cb_sanitize_file_name'])) { $file_name = call_user_func($conf['cb_sanitize_file_name'], $conf['file_name']); } else { $file_name = $conf['file_name']; } if ($conf['allow_extensions']) { if (is_string($conf['allow_extensions'])) { $conf['allow_extensions'] = preg_split('{\s*,\s*}', $conf['allow_extensions']); } if (!in_array(strtolower(pathinfo($file_name, PATHINFO_EXTENSION)), $conf['allow_extensions'])) { throw new Exception('', PLUPLOAD_TYPE_ERR); } } $file_path = rtrim($conf['target_dir'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file_name; $tmp_path = $file_path . ".part"; if ($conf['chunks']) { self::write_file_to("$file_path.dir.part" . DIRECTORY_SEPARATOR . $conf['chunk']); if ($conf['chunk'] == $conf['chunks'] - 1) { self::write_chunks_to_file("$file_path.dir.part", $tmp_path); } } else { self::write_file_to($tmp_path); } if (!$conf['chunks'] || $conf['chunk'] == $conf['chunks'] - 1) { if (is_callable($conf['cb_check_file']) && !call_user_func($conf['cb_check_file'], $tmp_path)) { @unlink($tmp_path); throw new Exception('', PLUPLOAD_SECURITY_ERR); } rename($tmp_path, $file_path); return array( 'name' => $file_name, 'path' => $file_path, 'size' => filesize($file_path) ); } return true; } catch (Exception $ex) { self::$_error = $ex->getCode(); return false; } }
/** * */ static function handle($conf = array()) { // 2H execution time @set_time_limit(7200); self::$_error = null; // start fresh $conf = self::$conf = array_merge(array('file_data_name' => 'file', 'tmp_dir' => ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload", 'target_dir' => false, 'cleanup' => true, 'max_file_age' => 48 * 3600, 'chunk' => isset($_REQUEST['chunk']) ? intval($_REQUEST['chunk']) : 0, 'chunks' => isset($_REQUEST['chunks']) ? intval($_REQUEST['chunks']) : 0, 'file_name' => isset($_REQUEST['name']) ? $_REQUEST['name'] : false, 'allow_extensions' => false, 'delay' => 0, 'cb_sanitize_file_name' => array(__CLASS__, 'sanitize_file_name'), 'cb_check_file' => false), $conf); try { if (!$conf['file_name']) { if (!empty($_FILES)) { $conf['file_name'] = $_FILES[$conf['file_data_name']]['name']; } else { throw new Exception('', PLUPLOAD_INPUT_ERR); } } // Cleanup outdated temp files and folders if ($conf['cleanup']) { self::cleanup(); } // Fake network congestion if ($conf['delay']) { usleep($conf['delay']); } // if (is_callable($conf['cb_sanitize_file_name'])) { // $file_name = call_user_func($conf['cb_sanitize_file_name'], $conf['file_name']); // } else { // $file_name = $conf['file_name']; // } $file_name = $conf['file_name']; // Check if file type is allowed if ($conf['allow_extensions']) { if (is_string($conf['allow_extensions'])) { $conf['allow_extensions'] = preg_split('{\\s*,\\s*}', $conf['allow_extensions']); } if (!in_array(strtolower(pathinfo($file_name, PATHINFO_EXTENSION)), $conf['allow_extensions'])) { throw new Exception('', PLUPLOAD_TYPE_ERR); } } $file_path = rtrim($conf['target_dir'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file_name; if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { $file_path = iconv('utf-8', 'gbk//IGNORE', $file_path); } $tmp_path = $file_path . ".part"; // Write file or chunk to appropriate temp location if ($conf['chunks']) { self::write_file_to("{$file_path}.dir.part" . DIRECTORY_SEPARATOR . $conf['chunk']); // Check if all chunks already uploaded if ($conf['chunk'] == $conf['chunks'] - 1) { self::write_chunks_to_file("{$file_path}.dir.part", $tmp_path); } } else { self::write_file_to($tmp_path); } // Upload complete write a temp file to the final destination if (!$conf['chunks'] || $conf['chunk'] == $conf['chunks'] - 1) { if (is_callable($conf['cb_check_file']) && !call_user_func($conf['cb_check_file'], $tmp_path)) { @unlink($tmp_path); throw new Exception('', PLUPLOAD_SECURITY_ERR); } rename($tmp_path, $file_path); return array('name' => $file_name, 'path' => $file_path, 'size' => filesize($file_path)); } // ok so far return true; } catch (Exception $ex) { self::$_error = $ex->getCode(); return false; } }