PHP file upload/download

Source: Internet
Author: User
Tags form post php file upload

Introduction: This is a detailed page for PHP file upload and download. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 329769 'rolling = 'no'>

1. php. ini configuration

; Resource limits; resource restrictions; maximum execution time of each script, in seconds; http://php.net/max-execution-time; note: this directive is hardcoded to 0 for the CLI sapimax_execution_time = 30; 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 .; note: this directive is hardcoded to-1 for the cli sapi; default value:-1 (unlimited); development value: 60 (60 seconds); production value: 60 (60 seconds); http://php.net/max-input-timemax_input_time = 60; maximum input variable nesting level; http://php.net/max-input-nesting-level;max_input_nesting_level = 64; maximum amount of memory a script may consume (128 MB); http://php.net/memory-limitmemory_limit = 128 m

Max_execution_time the maximum time for each script page to complete the operation, in seconds. If it is-1, there is no limit

Max_input_time maximum time for processing request data on each script page, in seconds. If it is-1, there is no limit

Memory_limit maximum memory that a script page can consume

 
; Maximum size of post data that PHP will accept.; http://php.net/post-max-sizepost_max_size = 8 m

The maximum value that PHP can receive through form post, including all items in the form.

 
;;;;;;;;;;;;;;;;;File uploads ;;;;;;;;;;;;;;;;;; whether to allow HTTP file uploads .; http://php.net/file-uploadsfile_uploads = on; temporary directory for HTTP uploaded files (will use system default if not; specified ).; http://php.net/upload-tmp-dirupload_tmp_dir = "E:/Wamp/tmp"; maximum allowed size for uploaded files .; http://php.net/upload-max-filesizeupload_max_filesize = 2 m

Whether file_uploads allows HTTP upload. The default value is on, which is enabled without modification.

The temporary storage directory when the upload_tmp_dir file is uploaded. If not specified, the default Temporary Folder is used.

Upload_max_filesize maximum number of objects that can be uploaded

2. Set three conditions on the page.

(1) set the type attribute to file.

(2) enctype = "multipart/form-Data" of Form"

(3) method = "Post"

 
<Form action = "" method = "Post" enctype = "multipart/form-Data"> <input name = "FILENAME" type = "file"/> <input type =" submit "value =" enter "/> </form>

<Input type = "hidden" name = "max_file_size" value = "1024000"/>

We recommend that you add a hidden field to the upload form to allow the maximum number of bytes to be uploaded. When the file is uploaded larger than 1 MB, the error value in $ files will return 2

3. the bool move_uploaded_file (string filename, string destination) function is used by PHP to upload files.

The temporary file name of the File Uploaded By filename, that is, $ _ FILES [tmp_name]

New path and name saved after destination upload

Move_uploaded_file () only saves the file in another place. This is for security considerations.

Bool is_uploaded_file (string filename) determines whether the file is post-uploaded.

<? Phpheader ('content-type: text/html; charset = UTF-8 '); $ tmparr =$ _ FILES ['filename']; if ($ tmparr ['error'] = 0) {If (is_uploaded_file ($ tmparr ['tmp _ name']) {If (move_uploaded_file ($ tmparr ['tmp _ name'], $ tmparr ['name']) {echo "uploaded successfully ";} else {echo "<SCRIPT> alert ('file invalid '); history. go (-1); </SCRIPT> ";}} else {echo" <SCRIPT> alert ('invalid operation'); history. go (-1); </SCRIPT> ";}} else {echo" <SCRIPT> alert ('upload error, error type :". $ tmparr ['error ']. "'); History. Go (-1); </SCRIPT>" ;}?>

4. The most common method for downloading through the download link and using the header () function.

More articles about "php file upload and download"

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/329769.html pageno: 12.

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.