<?PHP$fileinfo=$_files["MyFile"];functionUploadFile ($fileinfo,$allowext=Array(' jpeg ', ' jpg ', ' PND ', ' gif ', ' wbmp '),$flag=true,$maxsize=2097152){//Judging error Messagesif($fileinfo[' Error ']>0){ Switch($fileinfo[' Error ']) { Case1:$mes= "The upload file exceeds the value of the upload_max_filesize option in the PHP configuration file"; Break; Case2:$mes= "exceeds the limit size of form max_file_size"; Break; Case3:$mes= "File part is uploaded"; Break; Case4:$mes= "No Upload file selected"; Break; Case6:$mes= "No temp directory Found"; Break; Case7: Case8:$mes= "System Error"; Break; } Exit($mes); }//determine if the upload file type is in the specified type $allowext=Array(' jpeg ', ' jpg ', ' PND ', ' gif ', ' wbmp ');//define the allowed upload file types $ext=Strtolower(End(Explode(‘,‘,$fileinfo[' name ']));//intercept upload file extension if(!In_array($ext,$allowext))//determine if the extension of the uploaded file is in a defined type { Exit(' Illegal file type '); }//determine the upload file size $maxsize= 2097152;//write the maximum number of bytes, you count if($fileinfo[' Size ']>$maxsize) { Exit(' Upload file too large '); } //determine if the file was uploaded via HTTP post if(!Is_uploaded_file($fileinfo[' Tmp_name '])) { Exit(' File not uploaded by HTTP post ')); } //detects if a real picture type is true, but not what is considered a change $flag=true; if($flag) { if(!getimagesize($fileinfo[' Tmp_name '])) { Echo"Not a real picture type"; } } //determine if the folders stored on the server are not$path= ' uploads ';//file name stored on the server if(!file_exists($path)) { mkdir($path, 0777,true);//Create a directory if it does not exist chmod($path, 0777);//Add a permission }$uniname=MD5(uniqid(Microtime(true),true)).‘.‘.$ext;//by MD5 Encryption and other measures to name the filename, resulting in a unique file name $destination=$path.‘ /‘.$uniname; if(!Move_uploaded_file($fileinfo[' Tmp_name '],$destination))//Uploading Files { Echo"File upload Failed"; } return Array( ' NewName ' =$destination, ' size ' =$fileinfo[' Size '], ' type ' = =$fileinfo[' Type '] ); }
PHP Partial---Single-File Upload package class