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