Skip to content

Commit

Permalink
Give some real error codes back
Browse files Browse the repository at this point in the history
  • Loading branch information
odinho committed Oct 5, 2012
1 parent e26eecd commit f3c5152
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions examples/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down

0 comments on commit f3c5152

Please sign in to comment.