<?PHPHeader("Content-type:text/html;charset=utf8");//Get data Information$data=$_files;//iterate through the way to a single arrayforeach($data as $key=$val){ $arr=$val;}//determine if the file is validif(!Is_array($arr) ||Empty($arr)){ Echo"Invalid file"; die;}//get suffixif(!Empty($arr[' Name '])) { $info=PathInfo($arr[' Name ']); $st=$info[' DirName ']; $ext=$info[' extension '];}//determine the type of errorSwitch($arr[' Error ']){ Case1:Echo"The uploaded file exceeded the value of the Upload_max_filesize option limit in php.ini. "; die; Break; Case2:Echo"The size of the uploaded file exceeds the value specified by the Max_file_size option in the HTML form. "; die; Break; Case3:Echo"The file is only partially uploaded. "; die; Break; Case4:Echo"No files were uploaded. "; die; Break; Case6:Echo"Could not find the Temp folder. "; die; Break; Case7:Echo"File write failed. "; die; Break;}//set the type of file upload allowed$types=Array(' Image/gif ', ' image/jpeg ', ' image/jpg ', ' image/pjpeg ', ' image/x-png ', ' image/png ');//set the size of allowed file uploads$sizes= 204800;//less than 200kbif(!In_array($arr[' type '],$types)){ Echo"File type is not allowed";}if($arr[' Size ']>$sizes){ Echo"The file is too big"; die;}//determine if the file directory is presentif(!Is_dir('./upload ')){ mkdir(' Upload ');}//determine if the upload directory in the current directory exists for the file//if there is no upload directory, you need to create it, upload directory permissions for 777if(file_exists("upload/".$arr["Name"])){ Echo $arr["Name"]. "The file already exists. "; die;}Else{ //If the file is not present in the upload directory, upload the file to the upload directory $path= "upload/".$arr[' Name '].$st.$ext;//Path Move_uploaded_file($arr["Tmp_name"],$path);}Echo $path;
Object-Oriented---packaging file uploading ideas