From 3bad31691aa6689f1b185fd8f37ba91f0aba8673 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 23 Jun 2013 12:56:40 +0200 Subject: c/file: improve upload error handling Signed-off-by: Florian Pritz --- application/controllers/file.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'application/controllers') diff --git a/application/controllers/file.php b/application/controllers/file.php index 1c216aa15..851afa9b7 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -572,22 +572,30 @@ class File extends CI_Controller { // First error wins and is displayed, these shouldn't happen that often anyway. foreach ($files as $key => $file) { // getNormalizedFILES() removes any file with error == 4 - if ($file['error'] !== 0) { + if ($file['error'] !== UPLOAD_ERR_OK) { $this->output->set_status_header(400); + $message = ""; + + // ERR_OK only for completeness, if above ignores it $errors = 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" + UPLOAD_ERR_OK => "There is no error, the file uploaded with success", + UPLOAD_ERR_INI_SIZE => "The uploaded file exceeds the upload_max_filesize directive in php.ini", + UPLOAD_ERR_FORM_SIZE => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", + UPLOAD_ERR_PARTIAL => "The uploaded file was only partially uploaded", + UPLOAD_ERR_NO_FILE => "No file was uploaded", + UPLOAD_ERR_NO_TMP_DIR => "Missing a temporary folder", + UPLOAD_ERR_CANT_WRITE => "Failed to write file to disk", + UPLOAD_ERR_EXTENSION => "A PHP extension stopped the file upload", ); $this->data["msg"] = "Unknown error."; - if (isset($file)) { + if (isset($errors[$file['error']])) { $this->data["msg"] = $errors[$file['error']]; + } else { + $this->data["msg"] = "Unknown error code: ".$file['error'].". Please report a bug."; } + $this->load->view('header', $this->data); $this->load->view($this->var->view_dir.'/upload_error', $this->data); $this->load->view('footer'); -- cgit v1.2.3-24-g4f1b