File upload, determine file error type

Source: Internet
Author: User
Tags http post

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

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.