PHP File Upload

Source: Internet
Author: User

A php.ini configuration-related matters:

1.file_uploads=on; File upload must be turned on
2.upload_max_filesize= Max upload Size

3.upload_tmp_dir= File Upload Temp folder

The 4.post_max_size must be larger than the upload_max_filesize size
  

Second: The form submission notes:
1. The form submission must be an HTTP POST

2. form upload requires file form

3.enctype= "Multipart/form-data" only file upload is used

4. Hide the form: max_file_size=; limit the upload size in advance to avoid the file size after uploading in the PHP program;

<input type= "hidden" name= "max_file_size" value= "'. $maxSize. '"/>

Three: Accept the data:

1. Use $_files[] Super Global array; accept the obtained data

2. Copy files to the specified folder using copy ()

Step1: Use $_files[' pic ' [' Error ']; Check for errors

0: Means no errors;

1: Upload beyond the php.ini of the upload_max_filesize;

2: Upload beyond the max_file_size of the form;

3: No files are uploaded

4: Just a few other mistakes.

Step2: Limit file Upload size $_files[' pic ' [' size '];

Step3: Show file type:

1. Use $_files[' pic ' [' type ']===> image/gif image/png Image/ipp

2. Use $_files[' pic ' [' name '] ====>

$arr =explode ('. ', $_files[' pic ' [' name ']);

$arr [Count ($arr)-1];

Step4: Copy the file after uploading it:

  Is_uploads_file () to determine if the file was uploaded via http

if ($_files[' pic ' [' tmp_name ']) {

Move_uploaded_file (File,newloc);

}

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.