16 $this->
sizeLimit = min($this->
toBytes(ini_get(
'upload_max_filesize')), $this->
toBytes(ini_get(
'post_max_size')));
23 if (isset($_REQUEST[
'qqfilename']))
24 return $_REQUEST[
'qqfilename'];
45 1 == mt_rand(1, 1/$this->chunksCleanupProbability)){
55 $size = max(1, $this->
sizeLimit / 1024 / 1024) .
'M';
56 return array(
'error'=>
"Server error. Increase post_max_size and upload_max_filesize to ".$size);
59 if (!is_writable($uploadDirectory)){
60 return array(
'error' => sprintf(
$GLOBALS[
"STR_ADMIN_INSTALL_DIRECTORY_NOK"], $uploadDirectory));
63 if(!isset($_SERVER[
'CONTENT_TYPE'])) {
64 return array(
'error' =>
"No files were uploaded.");
65 }
else if (strpos(strtolower($_SERVER[
'CONTENT_TYPE']),
'multipart/') !== 0){
66 return array(
'error' =>
"Server error. Not a multipart request. Please set forceMultipart to default value (true).");
72 $size =
vb($file[
'size']);
80 if ($name === null || $name ===
''){
81 return array(
'error' =>
'File name empty.');
87 return array(
'error' =>
$GLOBALS[
"STR_FILE_EMPTY"]);
91 return array(
'error' =>
'File is too large.');
96 $pathinfo = pathinfo($name);
97 $ext = isset($pathinfo[
'extension']) ? $pathinfo[
'extension'] :
'';
99 if($this->allowedExtensions && !in_array(strtolower($ext), array_map(
"strtolower", $this->allowedExtensions))){
100 $these = implode(
', ', $this->allowedExtensions);
101 return array(
'error' =>
'File has an invalid extension, it should be one of '. $these .
'.');
106 $totalParts = isset($_REQUEST[
'qqtotalparts']) ? (int)$_REQUEST[
'qqtotalparts'] : 1;
108 if ($totalParts > 1){
111 $partIndex = (int)$_REQUEST[
'qqpartindex'];
112 $uuid = $_REQUEST[
'qquuid'];
114 if (!is_writable(
$chunksFolder) || !is_executable($uploadDirectory)){
115 return array(
'error' =>
"Server error. Chunks directory isn't writable or executable.");
118 $targetFolder = $this->
chunksFolder.DIRECTORY_SEPARATOR.$uuid;
120 if (!file_exists($targetFolder)){
121 mkdir($targetFolder);
124 $target = $targetFolder.
'/'.$partIndex;
125 $success = move_uploaded_file($_FILES[$this->inputName][
'tmp_name'], $target);
128 if ($success AND ($totalParts-1 == $partIndex)){
131 $this->uploadName = basename($target);
133 $target = fopen($target,
'w');
135 for (
$i=0;
$i<$totalParts;
$i++){
136 $chunk = fopen($targetFolder.
'/'.
$i,
"rb");
137 stream_copy_to_stream($chunk, $target);
144 for (
$i=0;
$i<$totalParts;
$i++){
145 $chunk = fopen($targetFolder.
'/'.
$i,
"r");
146 unlink($targetFolder.
'/'.
$i);
149 rmdir($targetFolder);
151 return array(
"success" =>
true);
155 return array(
"success" =>
true);
162 $this->uploadName = basename($target);
164 if (move_uploaded_file($file[
'tmp_name'], $target)){
165 return array(
'success'=>
true);
169 return array(
'error'=>
'Could not save uploaded file.' .
170 'The upload was cancelled, or server error encountered');
186 if (function_exists(
'sem_acquire')){
187 $lock = sem_get(ftok(__FILE__,
'u'));
192 $base = $pathinfo[
'filename'];
193 $ext = isset($pathinfo[
'extension']) ? $pathinfo[
'extension'] :
'';
194 $ext = $ext ==
'' ? $ext :
'.' . $ext;
201 while (file_exists($uploadDirectory . DIRECTORY_SEPARATOR . $unique . $ext)){
202 $suffix += rand(1, 999);
203 $unique = $base.
'-'.$suffix;
206 $result = $uploadDirectory . DIRECTORY_SEPARATOR . $unique . $ext;
214 if (function_exists(
'sem_acquire')){
227 if ($item ==
"." || $item ==
"..")
235 if (time() - filemtime($path) > $this->chunksExpireIn){
246 foreach (scandir($dir) as $item){
247 if ($item ==
"." || $item ==
"..")
250 unlink($dir.DIRECTORY_SEPARATOR.$item);
261 $last = strtolower($str[strlen($str)-1]);
263 case 'g': $val *= 1024;
264 case 'm': $val *= 1024;
265 case 'k': $val *= 1024;
removeDir($dir)
Removes a directory and all files contained inside.
getUploadName()
Get the name of the uploaded file.
getUniqueTargetPath($uploadDirectory, $filename)
Returns a path to use with this upload.
cleanupChunks()
Deletes all file parts in the chunks folder for files uploaded more than chunksExpireIn seconds ago...
handleUpload($uploadDirectory, $name=null)
Process the upload.
$GLOBALS['page_columns_count']
toBytes($str)
Converts a given size with units to bytes.
getName()
Get the original filename.
$chunksCleanupProbability
if(!empty($GLOBALS['site_parameters']['extensions_valides_'.$file_kind])) $uploader sizeLimit