PHP implements File Upload

Source: Internet
Author: User
PHP is easier to implement the file upload function. Here, we will record how to use it. The upload. php script that receives Multiple File Uploads at a time is as follows :? Php implements the backend for uploading and saving multiple files? Set encoding to UTF-8 to avoid Chinese garbled header (Content-Type: texthtml; charsetutf-8 );

PHP is easier to implement the file upload function. Here, we will record how to use it. The upload. php script that receives Multiple File Uploads at a time is as follows :? Php // is the backend for uploading and saving multiple files? // Set the encoding to UTF-8 to avoid Chinese garbled header ('content-Type: text/html; charset = UTF-8 ');

PHP is easier to implement the file upload function. Here, we will record how to use it.
The upload. php script that receives Multiple File Uploads at a time is as follows:

 $ Error) {if ($ error = UPLOAD_ERR_ OK) {// PHP constant UPLOAD_ERR_ OK value is 0, $ temp_name = $ fileArray ['tmp _ name'] [$ key]; $ file_name = $ fileArray ['name'] [$ key]; move_uploaded_file ($ temp_name, $ upload_dir. $ file_name); echo 'upload [file '. $ key. ':'. $ file_name. '] successful! ';} Else {echo' An error occurred while uploading [File '. $ key.': '. $ file_name! ';}}?>


For the size limit of uploaded files, there are two restrictions on nginx and php for my current nginx + php-fpm.
The default Request body is 1 MB. you can adjust it in the configuration file/etc/nginx. conf:

Http {include/etc/nginx/mime. types; default_type application/octet-stream ;? Client_max_body_size 10 M; # set the maximum body size ...}

If the client_max_body_size limit is exceeded, nginx returns a 413 response code indicating "Request Entity Too Large ".

PHP limits the size of post request content:
The/etc/php. ini file contains the following content:

?; Maximum amount of time each script may spend parsing request data. It's a good; idea to limit this time on productions servers in order to eliminate unexpectedly; long running scripts.; http://www.php.net/manual/en/info.configuration.php#ini.max-input-timemax_input_time = 60?; Maximum size of POST data that PHP will accept.; http://www.php.net/manual/en/ini.core.php#ini.post-max-sizepost_max_size = 10M?; Whether to allow HTTP file uploads.; http://www.php.net/manual/en/ini.core.php#ini.file-uploadsfile_uploads = On?; Maximum allowed size for uploaded files.; http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesizeupload_max_filesize = 10M

References:

Http://www.365mini.com/page/php-upload-file.htm

Http://www.php.net/manual/zh/features.file-upload.php

Http://forum.nginx.org/read.php? 2,139769, 139769 # msg-139769

Original article: PHP implements file upload.

©2014 laugh All over the world. All Rights Reserved.

Original article address: PHP implements the file upload function. Thanks to the original author for sharing.

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.