Permalink
Browse files

Give some real error codes back

  • Loading branch information...
1 parent e26eecd commit f3c515286014ec5407e33eefef5c09a2c65623c3 @odinho committed Oct 5, 2012
Showing with 13 additions and 3 deletions.
  1. +13 −3 examples/upload.php
View
@@ -80,7 +80,7 @@
$contentType = $_SERVER["CONTENT_TYPE"];
// Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
-if (!strstr($contentType, "multipart")) {
+if (strstr($contentType, "multipart")) {
if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
// Open temp file
$out = fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
@@ -98,8 +98,18 @@
@unlink($_FILES['file']['tmp_name']);
} else
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
- } else
- die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
+ } else {
+ $error_msg = "Unknown error (possibly POST_MAX_SIZE is smaller than MAX_FILE_SIZE?)";
+ if (isset($_FILES['file']['error']) && $_FILES['file']['error'] != 0) {
+ $errors = array(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");
+ $error_msg = "Error code {$_FILES['file']['error']} ({$errors[$_FILES['file']['error']]})";
+ }
+ die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file: '.$error_msg.'."}, "id" : "id"}');
+ }
} else {
// Open temp file
$out = fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");

0 comments on commit f3c5152

Please sign in to comment.