". * * THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP * DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * -------------------------------------------------------------------- * * This software consists of voluntary contributions made by many * individuals on behalf of the PHP Group. * * The PHP Group can be contacted via Email at group@php.net. * * For more information on the PHP Group and the PHP project, * please see . * * PHP includes the Zend Engine, freely available at * . */ // Exception class extension from: http://php.net/manual/en/features.file-upload.errors.php#89374 // Handles files error returning a proper error description class UploadException extends Exception { public function __construct($code) { $message = $this->codeToMessage($code); parent::__construct($message, 500); } private function codeToMessage($code) { switch ($code) { case UPLOAD_ERR_INI_SIZE: $message = 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; break; case UPLOAD_ERR_FORM_SIZE: $message = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was '. 'specified in the HTML form'; break; case UPLOAD_ERR_PARTIAL: $message = 'The uploaded file was only partially uploaded'; break; case UPLOAD_ERR_NO_FILE: $message = 'No file was uploaded'; break; case UPLOAD_ERR_NO_TMP_DIR: $message = 'Missing a temporary folder'; break; case UPLOAD_ERR_CANT_WRITE: $message = 'Failed to write file to disk'; break; case UPLOAD_ERR_EXTENSION: $message = 'File upload stopped by extension'; break; default: $message = 'Unknown upload error'; break; } return $message; } }