Uploading of PHP files

Source: Internet
Author: User
Tags php file upload

One, $_files array

  • $_files["File" ["Name"]: The original name of the uploaded file.
  • $_files["File" ["Type"]: Uploaded file type.
  • $_files["File" ["Size"]: The original size of the uploaded file.
  • $_files["File" ["Tmp_name"]: The staging location after uploading the file.
  • $_files["File" ["Error"]: Displays an error code if there is an error uploading the file

  • UPLOAD_ERR_OK value: 0; No error occurred and the file upload was successful.
  • upload_err_ini_size value: 1; The uploaded file exceeds the value of the Upload_max_filesize option limit in php.ini.
  • upload_err_form_size value: 2; The size of the uploaded file exceeds the value specified by the Max_file_size option in the HTML form. (We can specify the maximum number of bytes in the form form for input type= ' hidden ' name= ' max_file_size ' value= ' attachments ')
  • upload_err_partial value: 3; Only part of the file is uploaded.
  • upload_err_no_file value: 4; No files were uploaded.
  • Ii. Common file types

  • xls: application/vnd.ms-excel
  • xlsx: Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • ppt: application/vnd.ms-powerpoint
  • pptx: application/vnd.openxmlformats-officedocument.presentationml.presentation
  • Doc: Application/msword
  • docx: application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • Zip: application/x-zip-compressed
  • rar: application/x-zip-compressed
  • wmv: video/x-ms-wmv
  • mp3: audio/mpeg
  • mp4: Video/mp4
  • gif: image/git
  • JPEG: Image/jpeg or Image/pjpeg
    Note: For IE, the type of the recognized JPG file must be pjpeg, and for FireFox, it must be JPEG.
  • Third, the file upload process

  • After the file is uploaded, it is stored in the temp directory by default, and it must be removed from the temp directory or moved elsewhere, and if not, it will be deleted. That is, regardless of whether or not the upload succeeds, the files in the temp directory will be deleted after the script executes. So before you delete it, copy it or move it to another location using PHP's copy () or move_upload_file () function, and it's time to upload the file.

  • When uploading a file with a form, be sure to add the attribute content enctype= "Multipart/form-data", otherwise you will be reported an exception when obtaining the file information with $_files[filename].

  • Iv. saving uploaded files (move_uploaded_file)

    BOOL move_uploaded_file (String $filename, String $destination)

    Parameters:

  • filename: The file name of the uploaded file.

  • destination: Move files to this location

  • return value:

  • Returns TRUE upon success.

  • If filename is not a valid upload file, nothing happens and Move_uploaded_file () returns FALSE.

  • If filename is a legitimate upload file, but for some reason it cannot be moved, nothing happens and Move_uploaded_file () returns FALSE. A warning is also issued.

  • How far simple example of uploading a file

    Note:

    2. Script for processing files 1.php

     
      =30720) {#注意: The folder upload must already exist, otherwise it will be an error! if (file_exists ("upload/". $_files[' imgfile ' [' name '])) echo "File already exists, please do not repeat the upload. "; else Move_uploaded_file ($_files[' imgfile ' [' Tmp_name '], "upload/". $_files[' imgfile ' [' name ']); echo "File Upload successful! "; } else{echo "is not a JPEG or GIF picture format, or the file is less than 30k! please re-upload. "; } } ? >

    Vi. Acknowledgements

  • PHP file upload;
  • php:move_uploaded_file-manual;
  • The use of $_files variables in PHP;
  • On PHP?? Case, through? PHP $_files column?? On?? Text
  • PHP uploads common file types and $_files["file" ["type"].
  • Copyright NOTICE: This article for Lshare original article, need to reprint please contact me, have questions welcome comments or private messages.

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