Php file Upload

Source: Internet
Author: User
Tags php file upload
Php file upload 1, $ _ FILES array
  • $ _ FILES ["file"] ["name"]: The original name of the uploaded file.
  • $ _ FILES ["file"] ["type"]: Type of the uploaded file.
  • $ _ FILES ["file"] ["size"]: The original size of the uploaded file.
  • $ _ FILES ["file"] ["tmp_name"]: The temporary location of the uploaded file.
  • $ _ FILES ["file"] ["error"]: If an error occurs during file upload, the error code is displayed.

  • UPLOAD_ERR_ OKValue: 0. If no error occurs, the file is uploaded successfully.
  • UPLOAD_ERR_INI_SIZEValue: 1; the uploaded file exceeds the limit of the upload_max_filesize option in php. ini.
  • UPLOAD_ERR_FORM_SIZEValue: 2; the size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form. (You can specify the input type = 'den den 'name = 'MAX _ FILE_SIZE 'value = 'maximum number of bytes of the attachment' in the form ')
  • UPLOAD_ERR_PARTIALValue: 3; only part of the file is uploaded.
  • UPLOAD_ERR_NO_FILEValue: 4; no file is 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.doc ument
  • 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 jpg file type must be pjpeg, and for FireFox, it must be jpeg.
  • III. file upload process
  • After the file is uploaded, it is stored in the temporary directory by default. in this case, it must be deleted from the temporary directory or moved to another place. if it does not exist, it will be deleted. That is, no matter whether the upload is successful or not, the files in the temporary directory will be deleted after the script is executed. Therefore, you must use the PHPCopy ()OrMove_upload_file ()When the function copies or moves it to another location, the file upload process is completed.

  • When using form to upload files, attribute content must be added.Enctype = "multipart/form-data"Otherwise, an exception is reported when $ _ FILES [filename] is used to obtain the file information.

  • 4. Save the uploaded file (move_uploaded_file)

    BoolMove_uploaded_file(String $ filename, string $ destination)

    Parameters:

  • Filename: File name of the uploaded file.

  • Destination: Move the file to this location

  • Return value:

  • Returns TRUE if the call is successful.

  • If filename is not a valid file to be uploaded, no operation is performed. move_uploaded_file () returns FALSE.

  • If filename is valid but cannot be moved for some reason, no operation will occur. move_uploaded_file () returns FALSE. A warning is also issued.

  • 5. a simple file upload example

    Note:

    2. file processing script 1.php

     = 30720) {# Note: the folder upload must already exist. Otherwise, an error is returned! If (file_exists ("upload/". $ _ FILES ['imgfile'] ['name']) echo "the file already exists. do not upload it again. "; Else move_uploaded_file ($ _ FILES ['imgfile'] ['tmp _ name']," upload /". $ _ FILES ['imgfile'] ['name']); echo "the file is uploaded successfully! ";} Else {echo" is not in jpeg or gif format, or the file size is less than 30 kB! Upload again. ";}}?>
    6. thank you
  • Php file upload;
  • PHP: move_uploaded_file-Manual;
  • $ _ FILES variable usage in php;
  • On PHP ?? Case, thorough? PHP $ _ FILES? Column ?? Upper ?? Case;
  • Php uploads common file types and $ _ FILES ["file"] ["type"].
  • Copyright Disclaimer: This article is an original Lshare article. if you need to reprint it, please contact me. if you have any questions, please 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.