HTML code Upload file:
<formAction= "doaction.php"Method= "POST"enctype= "Multipart/form-data">Please select Upload file:<inputtype= "File"name= "MyFile" /><BR/> <inputtype= "Submit"value= "Upload" />
doaction.php File Code:
<meta charset= "Utf-8" ><?php//files//print_r ($_files), $filename =$_files[' myFile ' [' name ']; $type =$_files [' MyFile '] [' type ']; $tmp _name=$_files[' myFile ' [' tmp_name ']; $error =$_files[' myFile ' [' Error ']; $size =$_files[' myFile '] [' Size '];//determine the error message if ($error ==UPLOAD_ERR_OK) {//need to determine if the file is uploaded via HTTP post//is_uploaded_file ($tmp _name, $destination) ;//$destination = "uploads/". $filename; $destination = "uploads/". $filename; if (Is_uploaded_file ($tmp _name)) {if (move _uploaded_file ($tmp _name, $destination)) {$mes = "file upload succeeded";} else {$mes = "file move Failed";}} else {$mes = "File not uploaded by HTTP POST";}} else {switch ($error) {Case 1: $mes = "exceeds the size of the profile upload file"; Upload_err_ini_sizebreak;case 2: $mes = "exceeds the size of the form settings upload file"; Upload_err_form_sizebreak;case 3: $mes = "file part is uploaded"; Upload_err_partialbreak;case 4: $mes = "No files are uploaded"; Upload_err_no_filebreak;case 6: $mes = "No temporary directory found"; Upload_err_no_tmp_dirbreak;case 7: $mes = "file is not writable"; Upload_err_cant_writebreak;case 8: $mes = "File upload interrupted due to extension file"; Upload_err_extensionbreak;}} echo $mes;//server-side feedThe configuration of the row is configured in the configuration environment php.ini//file_uploads = on supports uploading files via HTTP Post//;upload_tmp_dir = Temporary file save Directory//upload_max_filesize = 2M The default value is 2M, the maximum upload size is 2m//post_max_size = 8M form sends the maximum value of the data in post, the default 8m//client is configured//<input type= "hidden" name= "max_file_size" Value= "/>" Here is case 2 the type of the error is determined//<input type= "file" Name= "MyFile" accept= "the MIME type,..."/>
File upload, determine file error type