An analysis of the methods of uploading files in PHP

Source: Internet
Author: User
Copy Code

Attention:

tag, the file upload must be specified as Multipart/form-data. Also, note the hidden value of the form option max_file_size in file upload.html, which limits the size of the uploaded file by setting its value. The value of max_file_size is just a suggestion to the browser, in fact it can be simply bypassed. The maximum number of uploaded files in PHP settings is not invalidated. However, it is best to add max_file_size to the form to improve the upload experience.

2,upload.php

    1. $f =& $HTTP _post_files[' Myfile ';
    2. $dest _dir= ' uploads '; Set upload Directory
    3. $dest = $dest _dir. '/'. Date ("Ymd"). " _ ". $f [' name ']; Set file name to date plus file name to avoid duplication
    4. $r =move_uploaded_file ($f [' Tmp_name '], $dest);
    5. chmod ($dest, 0755); Set the properties of the uploaded file
    6. Or
Copy Code

In the above example, the contents of the $_files array are as follows. Assume that the File upload field has the name UserFile (name is optionally named)

$_files[' UserFile ' [' Name '] The original name of the client machine file. The MIME type of the $_files[' userfile ' [' type '] file requires the browser to provide support for that information, such as "Image/gif". $_files[' userfile ' [' size '] the size of the uploaded file, in bytes. $_files[' UserFile '] [' tmp_name '] files are uploaded after the temporary file name stored on the server. $_files[' userfile ' [' Error '] and the file upload related error code value: 0; No error occurred and the file upload was successful. Value: 1; The uploaded file exceeds the value of the Upload_max_filesize option limit in php.ini. Value: 2; The size of the uploaded file exceeds the value specified by the Max_file_size option in the HTML form. Value: 3; Only part of the file is uploaded. Value: 4; No files were uploaded.
  • 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.