Php file upload process and summary _ PHP Tutorial

Source: Internet
Author: User
Tags form post http file upload php file upload
Php processes and summarizes the file upload process. PHP file upload process and various related aspects note: HTML basic submission through POST form PHP Upload steps the client uses HTTPPOST form to submit a file after uploading the file to store the PHP file upload process and the procedures involved notes

HTML basics

Submit through POST form

PHP Upload steps

  1. The client submits the form through http post.
  2. After the file is uploaded, it is stored in the default temporary directory. you can configure the php. ini attributes upload_tmp_dir and the PHP runtime environment variable TMPDIR to set the temporary directory. the putenv setting function in php is invalid.
  3. Use move_upload_file to move the upload from the temporary directory to the specified location (this step is not required if upload_tmp_dir has been set to the specified location)
  4. If the form does not select to upload FILES $ _ FILES ['userfile'] ['type'] = "", $ _ FILES ['userfile'] ['size'] = 0


Global predefined variables related to PHP

  • $ _ POST [array] is used to obtain parameters submitted in form POST mode.
  • $ _ FILES [array]
    • $ _ FILES ['userfile'] ['name'] original name of the client machine userfile = name attribute in the input control
    • $ _ FILES ['userfile'] ['type'] file MIME type
    • $ _ FILES ['userfile'] ['size'] size of the uploaded file (in bytes)
    • $ _ FILES ['userfile'] ['tmp _ name'] temporary file name stored on the server after the file is uploaded
    • $ _ FILES ['userfile'] ['error'] error code related to the file Upload

PHP functions

  • Is_upload_file (string $ filename) determines whether the file is uploaded through http post.
  • Move_upload_file ($ file, $ des) moves the uploaded file to a new location and checks whether the file is a valid file.

The file names involved in the parameters are all absolute paths.

Php. ini settings

  • File_uploads [boolean] whether HTTP File upload is allowed
  • Upload_max_filesize [integer] maximum size of the file to be uploaded. the default value is 2 MB.
  • Post_max_size [integer] maximum size allowed by POST data. value> upload_max_filesize
  • Memory_limit [integer] This value> post_max_size
  • Max_input_time [integer] the upload time starts when the script is executed, and all data reaches the server end. the default value is 60 s.
  • Upload_tmp_dir [string] temporary directory for file upload and storage. The PHP process owner can write permission.
  • Max_execution_time [integer] script execution time, which is not included in system call, sleep, database query, and file upload time

Error message

  • [0] UPLOAD_ERR_ OK file uploaded successfully
  • [1] the upload of the UPLOAD_ERR_INI_SIZE file exceeds UPLOAD_MAX_SIZE.
  • [2] UPLOAD_ERR_FORM_SIZE the size of the uploaded file exceeds MAX_FILE_SIZE
  • [3] Part of UPLOAD_ERR_PARTIAL file uploaded successfully
  • [4] no file is uploaded in UPLOAD_ERR_NO_FILE.
  • [6] The temporary folder cannot be found in UPLOAD_ERR_NO_TMP_DIR.
  • [7] An error occurred while writing the UPLOAD_ERR_CANT_WRITE file.

PHP server Upload security processing

  • Suffix check
  • Size limit
  • Content-Type check
  • If the image uses getimagesize for file type check
  • Set the application directory and upload directory access permissions on the server.
Articles you may be interested in
  • PHP analyzes the file header information to determine the type of the uploaded file
  • Php file upload configuration tutorial
  • Jquery + html + php implement Ajax without refreshing file Upload
  • PHP is the safest and most practical solution to determine the type of uploaded files
  • Php implements batch file compression, packaging, and downloading
  • Php obtains all the files in the directory and saves the results to the array program.
  • Php determines whether the string is full of English, pure Chinese, and a combination of Chinese and English
  • Powerful PHP image processing class (Watermark, transparency, zoom, sharpen, rotate, flip, cut, reversed)

HTML basics submit PHP Upload steps through POST form the client submits files through the http post form Upload After storage...

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