Current Path : /var/www/html/clients/nsmk.e-nk.ru/application/maxsite/plugins/file_manager/php/ |
Current File : /var/www/html/clients/nsmk.e-nk.ru/application/maxsite/plugins/file_manager/php/upload.php |
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); global $encoding; if (PHP_OS == 'WINNT') $encoding = 'CP1251'; else $encoding = 'UTF-8'; // Code for Session Cookie workaround if (isset($_POST["PHPSESSID"])) { session_id($_POST["PHPSESSID"]); } else if (isset($_GET["PHPSESSID"])) { session_id($_GET["PHPSESSID"]); } session_start(); // Check post_max_size (http://us3.php.net/manual/en/features.file-upload.php#73762) $POST_MAX_SIZE = ini_get('post_max_size'); $unit = strtoupper(substr($POST_MAX_SIZE, -1)); $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1))); if (!isset($_SERVER['CONTENT_LENGTH'])) { echo json_encode(array('error'=>'no CONTENT_LENGTH')); exit(0); } if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) { header("HTTP/1.1 500 Internal Server Error"); // This will trigger an uploadError event in SWFUpload HandleError("POST exceeded maximum allowed size."); //echo json_encode( "POST exceeded maximum allowed size."); exit(0); } // Settings //$save_path = getcwd() . "/uploads/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment) //$save_path = $_SERVER['DOCUMENT_ROOT'] .'/'. $_REQUEST['folder']; $folder = ''; $_folder = ''; if(isset($_POST['folder'])) { $u_folder = $_POST['folder']; $folder = mb_convert_encoding($_POST['folder'], $encoding, "UTF-8"); } $save_path = $_POST['uploads_dir'] . $folder; $upload_name = "Filedata"; $max_file_size_in_bytes = 2147483647; // 2GB in bytes // no use $extension_whitelist = array("jpg", "gif", "png"); // Allowed file extensions // no use $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format) // Other variables $MAX_FILENAME_LENGTH = 260; $file_name = ""; $file_extension = ""; $uploadErrors = array( 0=>"There is no error, the file uploaded with success", 1=>"Размер загружаемого файла превышает указание upload_max_filesize установленное в php.ini", 2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 3=>"The uploaded file was only partially uploaded", 4=>"No file was uploaded", 6=>"Missing a temporary folder" ); // Validate the upload if (!isset($_FILES[$upload_name])) { HandleError("No upload found in \$_FILES for " . $upload_name); exit(0); } else if (isset($_FILES[$upload_name]["error"]) && $_FILES[$upload_name]["error"] != 0) { HandleError($uploadErrors[$_FILES[$upload_name]["error"]]); exit(0); } else if (!isset($_FILES[$upload_name]["tmp_name"]) || !@is_uploaded_file($_FILES[$upload_name]["tmp_name"])) { HandleError("Upload failed is_uploaded_file test."); exit(0); } else if (!isset($_FILES[$upload_name]['name'])) { HandleError("File has no name."); exit(0); } // Validate the file size (Warning: the largest files supported by this code is 2GB) $file_size = @filesize($_FILES[$upload_name]["tmp_name"]); if (!$file_size || $file_size > $max_file_size_in_bytes) { HandleError("File exceeds the maximum allowed size"); exit(0); } if ($file_size < 0) { // <= HandleError("File size outside allowed lower bound"); exit(0); } $u_file_name = basename($_FILES[$upload_name]['name']); $file_name = mb_convert_encoding($u_file_name, $encoding, "UTF-8"); if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path . $file_name)) { HandleError("File could not be saved: " . $save_path . $file_name); exit(0); } else { chmod($save_path . $file_name, 0666); @chown($save_path . $file_name, get_current_user()); // стоит запрет на хостинге } clearstatcache(); $CI = & get_instance(); $CI->load->helper('file'); require_once "file.inc.php"; $out = array(); $out['folder'] = $u_folder; $out['file'] = getFile($save_path, $file_name); if (isset($fm_allowed_image[$out['file']['ext']]) && isset($_POST["tasks"])) { require_once "thumbnail.inc.php"; $t = array(); $tr = array(); $dim = GetImageSize($save_path . $file_name, &$info); foreach (json_decode($_POST['tasks']) as $taskname => $task) { if ($task->state == TRUE) { $t[$taskname] = run_task($taskname, $task, $dim, $save_path, $file_name); if($r = get_info_task($taskname, $save_path, $file_name)) $tr[$taskname] = $r; if ($taskname == 'image') $out['file']['filesize'] = $r['filesize']; } // для проверки $out['tasks'][] = $task; } $out['file']['list'] = $tr; $out['file']['tasks'] = $t; } echo json_encode($out); function HandleError($message) { global $save_path,$file_name; echo json_encode(array('error'=>$message, 'folder'=>$save_path . $file_name)); } ?>