Search
 
SCRIPT & CODE EXAMPLE
 

PHP

error import php

[EDIT BY danbrown AT php DOT net: This code is a fixed version of a note originally submitted by (Thalent, Michiel Thalen) on 04-Mar-2009.]


This is a handy exception to use when handling upload errors:

<?php

class UploadException extends Exception
{
    public function __construct($code) {
        $message = $this->codeToMessage($code);
        parent::__construct($message, $code);
    }

    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;
    }
}

// Use
if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
//uploading successfully done
} else {
throw new UploadException($_FILES['file']['error']);
}
?>
Comment

PREVIOUS NEXT
Code Example
Php :: breaking long array in php 
Php :: Laravel Http client retry request if fail 
Php :: check if valid date format entered inside the excel import php 
Php :: SymfonyComponentHttpKernelExceptionNotFoundHttpException: POST http://localhost/post 
Php :: How to on auto_recording using zoom api in php 
Php :: laravel artisan command run in route 
Php :: Registering a variable with $_SESSION. 
Php :: how to know app_basepath 
Php :: what does the initals of php stand for? 
Php :: php console lofarray values 
Php :: php print array as string 
Php :: Best Performance monitoring tools for php 
Php :: validation ignored rules 
Php :: php foreach show only 4 
Php :: AUTO TRANSFER OF DATA FROM SYBASE TABLE TO PHPMYSQL TABLE 
Php :: verta sample jalali laravel problem return object 
Php :: Add class to menu anchors 
Php :: php ?: 
Php :: swift mailer 530 Must issue a STARTTLS command first. 
Php :: php multiple array to single array 
Php :: ERROR: Module mpm_event is enabled - cannot proceed due to conflicts. It needs to be disabled first! Considering conflict mpm_worker for mpm_prefork: ERROR: Could not enable dependency mpm_prefork for php7.2, aborting 
Php :: install phpmyadmin debian 11 
Php :: define value in php 
Php :: php simple server 
Php :: change php version 
Java :: how to get all the names of the files in a folder in java? 
Java :: spigot cancel repeating task 
Java :: java pause 
Java :: java hashmap entryset 
Java :: How to solve towers of hanoi problem? 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =