Using PHP to upload files

Source: Internet
Author: User
PHP (HypertextPreprocessor) is an embedded HTML language (similar to ASP on IIS ). The peculiar syntax of PHP is mixed with the new syntax of C, Java, Perl and PHP. It can execute dynamic web pages faster than CGI or Perl. In addition, Hypertext Preprocessor is an embedded HTML language (similar to ASP on IIS ). The peculiar syntax of PHP is mixed with the new syntax of C, Java, Perl and PHP. It can execute dynamic web pages faster than CGI or Perl. In addition, the Web backend CGI program written in PHP can be easily transplanted to different system platforms.

When we are building a website, visitors are required to participate in the construction of the website, which requires us to get articles and images from the visitors. Therefore, file upload is essential to web pages. Now I am using the popular programming language PHP and using two methods to illustrate its function implementation.

I. use php file functions for Upload
This code is divided into two files, one is upload.html and the other is upload. php.


Select Upload File: upload.html code:

----------------------------------------------------------------------

   Upload file Form

  

  

  

  

----------------------------------------------------------------------

* ** Clarification ***

1. be careful This is a tag. to upload a file, you must specify it as multipart/form-data. Otherwise, the server will not know what you are doing!

2xx is the hidden field of the form option MAX_FILE_SIZE in the file upload.html.

Its Value can limit the size of the uploaded file.


Process the uploaded file: the upload. php code is as follows:

----------------------------------------------------------------------

  

  

   Process uploaded files

  

  

  
Copy ($ userfile, 'newfile ');

Echo $ userfile. '-name of the temporary file that the user uploads to the server
';

Echo $ userfile_name. '-original name of the file on the user's machine
';

Echo $ userfile_size. '-actual number of bytes of the uploaded file
';

Echo $ userfile_type. '-if the user's browser provides this information, it represents the mime type. For example, image/gif
';

?>

  

  

----------------------------------------------------------------------

* ** Clarification ***

1. the php file function copy () is applied to copy the files uploaded to the temporary directory to a specific directory and rename it 'newfile '.

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.