File Upload, Java file upload _php tutorial

Source: Internet
Author: User

File Upload, Java file upload


File upload is divided into two steps

1 , the client user uploads;

A) A form field is required to inject the file to be uploaded,

<type= "file"  name= "file"/>

b) The user chooses the file to be uploaded

c) Click on the user to send the file to the server

2 , the server receives

The form form uses the Post submission method.

* Note: Get,post cannot submit binary files, but post submission adds a property to complete.

<action= "file.php"  method= "POST"   Enctype= "Multipart/form-data">

HTML section:

HTML section:
  DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>File Upload 
     title> 
      head><body>  <form  action= "file.php"  method= "POST" enctype = "Multipart/form-data" > < input type = "File" name = "File" /> < input type = "Submit" value = "Submit" />  
       form> body>  
    
                           
 

PHP section

Var_dump ($_files) was found to be an array

array  ' File ' = =     array      string ' 4.jpg ' (length=5      )string ' Image/jpeg ' ( length=10)      string ' F:\wamp\tmp\php904D.tmp ' (length=23)      ' ERROR ' = int 0      ' size ' = = int 273665

Data validation is performed at this time

A) Find the error point based on a two-dimensional array;

Switch ($_files[' file '] [' ERROR '])    {case ' 0 ':        echo "upload succeeded";          Break ;      Case ' 1 ': Case     ' 2 ':        header(' refresh:3;url=file.html ');         Echo "File size exceeds server limit";          Break ;      Case ' 3 ':        header(' refresh:3;url=file.html ');         Echo "The file only partially uploaded successfully"        ;  Break ;      Case ' 4 ':        header(' refresh:3;url=file.html ');         Echo "No files selected, please re-select the file and submit";          Break ;     default:        echo "File upload Failed";}


b) After the file upload is successful, it is placed in the specified temp directory, which needs to be changed to the desired file.

PHP has a function to complete,move_uploaded_file ()

eg

Move_uploaded_file ($_files$_files[' file '] [' name ']);

Note: tmp_name, files are uploaded to the server's temp directory,

' Name ', the file name of the file locally on the client.

http://www.bkjia.com/PHPjc/1128377.html www.bkjia.com true http://www.bkjia.com/PHPjc/1128377.html techarticle file Upload, java file Upload file upload is divided into two steps 1, the client user uploads; a) a form field is required to inject the file to be uploaded, input type = "File" name = " ...

  • 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.