1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 20:30:39 +02:00

Fix for drag-n-drop upload.

This commit is contained in:
Cameron
2018-08-26 15:27:59 -07:00
parent f958f66dcb
commit e392fd5740
2 changed files with 25 additions and 5 deletions

View File

@@ -1519,8 +1519,8 @@ class e_form
$('#".$name_id."_prev').dropzone({ $('#".$name_id."_prev').dropzone({
url: '".e_JS."plupload/upload.php?for=".$cat."', url: '".e_JS."plupload/upload.php?for=".$cat."',
createImageThumbnails: false, createImageThumbnails: false,
uploadMultiple :true, uploadMultiple :false,
dictDefaultMessage: \"".defset('LAN_UI_DROPZONE_DROP_FILES', "Drop files here to upload")."\", dictDefaultMessage: \"".defset('LAN_UI_DROPZONE_DROP_FILES', "Drop files here to upload")."\",
maxFilesize: ".(int) ini_get('upload_max_filesize').", maxFilesize: ".(int) ini_get('upload_max_filesize').",
success: function (file, response) { success: function (file, response) {

View File

@@ -54,6 +54,10 @@
$fileName = $_FILES['file']['name']; $fileName = $_FILES['file']['name'];
} }
// $array = array("jsonrpc" => "2.0", "error" => array('code'=>$_FILES['file']['error'], 'message'=>'Failed to move file'), "id" => "id", 'data'=>$_FILES );
// Make sure the fileName is unique but only if chunking is disabled // Make sure the fileName is unique but only if chunking is disabled
if($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) if($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName))
{ {
@@ -145,9 +149,25 @@
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
} }
} }
else else // Misc Error.
{ {
die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file. '.ini_get('upload_max_filesize').'"}, "id" : "id"}'); $phpFileUploadErrors = array(
0 => 'There is no error, the file uploaded with success',
1 => 'The uploaded file exceeds the upload_max_filesize directive in 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',
7 => 'Failed to write file to disk.',
8 => 'A PHP extension stopped the file upload.',
);
$err = (int) $_FILES['file']['error'];
$array = array("jsonrpc" => "2.0", "error" => array('code'=>$err, 'message'=> $phpFileUploadErrors[$err]), "id" => "id", 'data'=>$_FILES );
echo json_encode($array);
exit;
} }
@@ -195,7 +215,7 @@
if(e107::getFile()->isClean($filePath) !== true) if(e107::getFile()->isClean($filePath) !== true)
{ {
@unlink($filePath); @unlink($filePath);
die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Bad File Detected."}, "id" : "id"}'); die('{"jsonrpc" : "2.0", "error" : {"code": 104, "message": "Bad File Detected."}, "id" : "id"}');
} }