@ 2014-05-21T08:35:52Z <?php
/**
* upload.php
*
* Copyright 2013, Moxiecode Systems AB
* Released under GPL License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*/
#!! IMPORTANT:
#!! this file is just an example, it doesn't incorporate any security checks and
#!! is not recommended to be used in production environment as it is. Be sure to
#!! revise it and customize to your needs.
// Make sure file is not cached (as it happens for example on iOS devices)
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
/*
// Support CORS
header("Access-Control-Allow-Origin: *");
// other CORS headers if any...
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
exit; // finish preflight CORS requests here
}
*/
// 5 minutes execution time
@set_time_limit(5 * 60);
// Uncomment this one to fake upload time
// usleep(5000);
// Settings
//$targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
$targetDir = 'uploads';
$cleanupTargetDir = true; // Remove old files
$maxFileAge = 5 * 3600; // Temp file age in seconds
// Create target dir
if (!file_exists($targetDir)) {
@mkdir($targetDir);
}
// Get a file name
if (isset($_REQUEST["name"])) {
$fileName = $_REQUEST["name"];
} elseif (!empty($_FILES)) {
$fileName = $_FILES["file"]["name"];
} else {
$fileName = uniqid("file_");
}
public static function normalizeString ($str = '')
{
$str = strip_tags($str);
$str = preg_replace('/[\r\n\t ]+/', ' ', $str);
$str = preg_replace('/[\"\*\/\:\<\>\?\'\|]+/', ' ', $str);
$str = strtolower($str);
$str = html_entity_decode( $str, ENT_QUOTES, "utf-8" );
$str = htmlentities($str, ENT_QUOTES, "utf-8");
$str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
$str = str_replace(' ', '-', $str);
$str = rawurlencode($str);
$str = str_replace('%', '-', $str);
return $str;
}
$filename = $this->normalizeString($filename)
$filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;
// Chunking might be enabled
$chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
$chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
// Remove old temp files
if ($cleanupTargetDir) {
if (!is_dir($targetDir) || !$dir = opendir($targetDir)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
}
while (($file = readdir($dir)) !== false) {
$tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file;
// If temp file is current file proceed to the next
if ($tmpfilePath == "{$filePath}.part") {
continue;
}
// Remove temp file if it is older than the max age and is not the current file
if (preg_match('/\.part$/', $file) && (filemtime($tmpfilePath) < time() - $maxFileAge)) {
@unlink($tmpfilePath);
}
}
closedir($dir);
}
// Open temp file
if (!$out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb")) {
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
}
if (!empty($_FILES)) {
if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
}
// Read binary input stream and append it to temp file
if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
}
} else {
if (!$in = @fopen("php://input", "rb")) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
}
}
while ($buff = fread($in, 4096)) {
fwrite($out, $buff);
}
@fclose($out);
@fclose($in);
// Check if file has been uploaded
if (!$chunks || $chunk == $chunks - 1) {
// Strip the temp .part suffix off
rename("{$filePath}.part", $filePath);
}
// Return Success JSON-RPC response
die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.6.5 0.010 0.070 17.57 5.6.4 0.010 0.077 17.47 5.6.3 0.000 0.060 17.54 5.6.2 0.010 0.060 17.53 5.6.1 0.003 0.053 17.54 5.6.0 0.010 0.077 17.50 5.5.21 0.013 0.050 17.43 5.5.20 0.013 0.050 17.32 5.5.19 0.010 0.037 17.34 5.5.18 0.003 0.050 17.30 5.5.16 0.010 0.077 17.27 5.5.15 0.000 0.083 17.37 5.5.14 0.003 0.050 17.33 5.5.13 0.007 0.043 17.26 5.5.12 0.007 0.080 17.41 5.5.11 0.007 0.057 17.30 5.5.10 0.013 0.070 17.20 5.5.9 0.007 0.043 17.23 5.5.8 0.000 0.080 17.29 5.5.7 0.007 0.080 17.23 5.5.6 0.003 0.080 17.26 5.5.5 0.003 0.040 17.32 5.5.4 0.010 0.030 17.31 5.5.3 0.003 0.037 17.32 5.5.2 0.003 0.040 17.18 5.5.1 0.003 0.040 17.21 5.5.0 0.003 0.037 17.22 5.4.37 0.017 0.063 18.96 5.4.36 0.000 0.087 19.14 5.4.35 0.017 0.060 18.98 5.4.34 0.010 0.033 19.27 5.4.32 0.007 0.060 19.06 5.4.31 0.013 0.073 19.14 5.4.30 0.010 0.060 19.13 5.4.29 0.003 0.080 18.95 5.4.28 0.007 0.080 19.11 5.4.27 0.007 0.063 19.06 5.4.26 0.010 0.060 19.09 5.4.25 0.010 0.050 19.01 5.4.24 0.007 0.080 19.03 5.4.23 0.007 0.063 19.13 5.4.22 0.000 0.057 19.04 5.4.21 0.007 0.063 18.98 5.4.20 0.000 0.040 19.04 5.4.19 0.007 0.047 19.26 5.4.18 0.007 0.040 19.09 5.4.17 0.000 0.040 19.09 5.4.16 0.007 0.033 19.02 5.4.15 0.003 0.037 19.25 5.4.14 0.007 0.030 16.29 5.4.13 0.007 0.030 16.38 5.4.12 0.003 0.050 16.30 5.4.11 0.003 0.037 16.38 5.4.10 0.003 0.033 16.41 5.4.9 0.003 0.053 16.39 5.4.8 0.007 0.037 16.39 5.4.7 0.013 0.023 16.57 5.4.6 0.007 0.033 16.43 5.4.5 0.003 0.033 16.36 5.4.4 0.003 0.033 16.62 5.4.3 0.003 0.033 16.36 5.4.2 0.003 0.033 16.46 5.4.1 0.000 0.037 16.45 5.4.0 0.000 0.037 15.83 5.3.29 0.007 0.060 14.63 5.3.28 0.013 0.057 14.57 5.3.27 0.010 0.030 14.60 5.3.26 0.010 0.030 14.43 5.3.25 0.000 0.037 14.53 5.3.24 0.007 0.033 14.58 5.3.23 0.000 0.040 14.57 5.3.22 0.000 0.040 14.55 5.3.21 0.000 0.040 14.39 5.3.20 0.003 0.047 14.39 5.3.19 0.000 0.040 14.65 5.3.18 0.000 0.040 14.52 5.3.17 0.007 0.040 14.54 5.3.16 0.007 0.030 14.65 5.3.15 0.003 0.033 14.55 5.3.14 0.007 0.030 14.52 5.3.13 0.000 0.043 14.47 5.3.12 0.003 0.037 14.50 5.3.11 0.007 0.033 14.47 5.3.10 0.003 0.037 13.82 5.3.9 0.000 0.037 13.98 5.3.8 0.010 0.027 13.94 5.3.7 0.003 0.043 14.01 5.3.6 0.007 0.030 13.95 5.3.5 0.000 0.037 13.71 5.3.4 0.003 0.037 13.89 5.3.3 0.003 0.033 13.89 5.3.2 0.000 0.037 13.64 5.3.1 0.007 0.030 13.45 5.3.0 0.007 0.070 13.73
preferences:dark mode live preview
140.58 ms | 1394 KiB | 7 Q