Notes for PHP File Upload implementation

Source: Internet
Author: User

Upload interface


Assuming that the file domain name in this interface is userfile, we can open a file selection window through browsing. After the selection is complete, the text box will show the complete path of the real file on the local machine. After you press upload, the file will be transferred to the temporary directory on the server and renamed as php ?. Tmp, where the question mark is a random number.

The html code is as follows:

<Form action = "upload. php" method = "post" enctype = "multipart/form-data" name = "form1">

<Input type = "hidden" name = "MAX_FILE_SIZE" value = "30000">

<Input name = "userfile" type = "file">

<Input type = "submit" name = "Submit" value = "Upload">

</Form>

After being transferred to another file upload. php, you can use the following variables to access information related to the file.

$ Userfile_name upload document name

$ Userfile_tmp_name temporary name for saving the uploaded document

$ Userfile_size size of the uploaded document, in bytes

$ Userfile_type the mime type of the document to be uploaded

The preceding variables are normal in windows + apache, but the following variables can be used if they are inaccessible in linux.

$ _ FILE ['userfile'] ['name'] is equivalent to $ userfile_name

$ _ FILE ['userfile'] ['tmp _ name'] is equivalent to $ userfile_tmp_name

$ _ FILE ['userfile'] ['SIZE'] is equivalent to $ userfile_size

$ _ FILE ['userfile'] [type] is equivalent to $ userfile_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.