PHP processing File upload process and summary _php tutorial

Source: Internet
Author: User
Tags configuration php form post http post php language php server php file upload
PHP file Upload processing process and the various aspects involved in the attention

HTML Basics

Submit via post form

PHP Upload Steps

    1. Client submits via HTTP POST form
    2. Files are stored in the default temp directory after uploading, configuration php.ini properties Upload_tmp_dir and PHP Runtime environment variables Tmpdir can set temporary directory, PHP language function putenv Settings invalid
    3. Use Move_upload_file to move uploads from a temporary directory to a specified location (this step is not required if Upload_tmp_dir is already set to the specified location)
    4. If the form does not choose to upload the file $_files[' userfile ' [' type '] = = "", $_files[' userfile ' [' Size ']== 0

PHP related global pre-defined variables

    • $_post [array] used to get the parameters submitted by the form POST
    • $_files [Array]
      • $_files[' UserFile ' [' Name '] Client machine original name UserFile = = Name property in the input control
      • $_files[' userfile ' [' type '] file MIME type
      • $_files[' userfile ' [' size '] uploaded file size (bytes)
      • $_files[' UserFile '] [' tmp_name '] file is uploaded and the server stores the temporary file name
      • $_files[' userfile ' [' Error '] and the file upload related error code

PHP related functions

    • Is_upload_file (string $filename) to determine if the file was uploaded via HTTP post
    • Move_upload_file ($file, $des) Move the uploaded file to a new location and check that file is a legitimate upload

The file names involved in the parameters are absolute paths

PHP.ini Related Settings

    • File_uploads [Boolean] allows HTTP file uploads
    • upload_max_filesize [integer] maximum size of uploaded file, default 2M
    • post_max_size [Integer]post data allows the maximum size, this value >upload_max_filesize
    • Memory_limit [integer] This value >post_max_size
    • max_input_time [integer] Upload time script execution start count to data all arrive server up to, default 60s
    • Upload_tmp_dir [string] File Upload file temp directory, PHP process owner user writable permission
    • max_execution_time [integer] Script execution time, system call, sleep, database query, file upload time not included

Error message

    • [0] Upload_err_ok File upload successful
    • [1] upload_err_ini_size file upload more than upload_max_size
    • [2] upload_err_form_size upload file size exceeds max_file_size
    • [3] upload_err_partial file partial upload success
    • [4] Upload_err_no_file no files were uploaded
    • [6] Upload_err_no_tmp_dir cannot find the Temp folder
    • [7] Upload_err_cant_write file write failed

PHP Server upload Security processing

    • Suffix name check
    • Size limit
    • Content-type Check
    • If the picture is using getimagesize for file type checking
    • Set the app directory and upload directory access permissions from the server separately

Articles you may be interested in

    • PHP parsing file header information to determine the type of upload file
    • PHP File Upload related configuration tutorial
    • jquery+html+php implement Ajax no-refresh file upload
    • PHP determines the safest and most realistic solution for uploading file types
    • PHP implementation of the file batch compression package download
    • PHP gets all the files in the directory and saves the results to an array of programs
    • PHP to determine whether the string is in English, pure Chinese, the method of combination of English
    • Powerful PHP Image processing class (watermark, transparency, zoom, sharpen, rotate, flip, cut, invert)

http://www.bkjia.com/PHPjc/764195.html www.bkjia.com true http://www.bkjia.com/PHPjc/764195.html techarticle php File Upload processing process as well as involved in all aspects of the HTML foundation through the Post form to submit the PHP upload Step client through the HTTP Post form submission file upload after the 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: 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.