Php disposal file Upload

Source: Internet
Author: User
Php processes file uploads & lt ;? Php *** @ todo: Process File uploads * @ Author: yuguibin * @ date: 2014-03-20 * if (! Empty ($ _ FILES [file]) {& nbsp; $ files $ _ FILES [file]; file name, name of the file box & nbs php processing file Upload
/**
* @ Todo: process file uploads.
* @ Author: yuguibin
* @ Date: 2014-03-20
*/
If (! Empty ($ _ FILES ["file"])
{
$ Files = $ _ FILES ["file"]; // file name, the name of the file box
If (! Empty ($ files ['error']) {// error message
Switch ($ files ['error'])
{
Case "1": $ error = array ('status' => FALSE, 'MSG '=> "exceeds the value of php. value restricted by the upload_max_filesize option in ini "); break;
Case "2": $ error = array ('status' => FALSE, 'MSG '=> "The size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form "); break;
Case "3": $ error = array ('status' => FALSE, 'MSG '=> "only part of the file is uploaded"); break;
Case "4": $ error = array ('status' => FALSE, 'MSG '=> "No file is uploaded"); break;
Case "6": $ error = array ('status' => FALSE, 'MSG '=> "temporary folder not found"); break;
Case "7": $ error = array ('status' => FALSE, 'MSG '=> "file write failed"); break;
Default: $ error = array ('status' => FALSE, 'MSG '=> "Unknown error"); break;
}
Return $ error;
}
$ Path = "upload/"; // upload path
If (! File_exists ($ path ))
{
If (! Mkdir ($ path, 0700 ))
{
$ Info = array ("status" => FALSE, "msg" => "The file directory does not exist ");
Return $ info;
}
}
// File format that can be uploaded
$ Extension = strtolower (end (explode ("/", $ files ["type"]);
$ Tp = array ("gif", "jpeg", "jpg", "png", "bmp ");
If (! In_array ($ extension, $ tp ))
{
$ Info = array ("status" => FALSE, "msg" => "File Format Error ");
Return $ info;
}
$ Filename = $ path. date ("YmdHis"). ".". $ extension;
If (@ move_uploaded_file ($ files ["tmp_name"], $ filename ))
{
$ Info = array ("status" => TRUE, "msg" => $ filename );
Return $ info;
}
Else
{
$ Info = array ("status" => FALSE, "msg" => "failed to move files ");
Return $ info;
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.