PHP File Upload principle of simple introduction

Source: Internet
Author: User
PHP File Upload principle simple analysis, learning PHP friends can refer to, indeed more than the ASP is much simpler.

Form uploads can only be used in MULTIPART/FORM-DATA encoded format
$_files system functions;
$_files[' myFile ' [' name '] file name
$_files[' myFile ' [' type '] file types, limited by server
image/**
Image/x-png
Application/x-zip-compressed
$_files[' myFile ' [' Size '] upload file size
$_files[' myFile ' [' tmp_name '] save temporary file name after uploading service
$_files[' myFile ' [' ERROR '] error code;
0 Success 1 exceeds php.ini size 2 value specified by Max_file_size option
3 only partially uploaded 5 upload file size is 0

Move_uploaded_file (temporary file, target location and file name);
Functions for moving files to the target location after uploading
Is_uploaded_file (MIME);
To determine the file function of the upload MIME type

The code is as follows:

<form enctyoe= "Multipart/form-data" method= "post" name= "Upload" > < Input name= "upfile" name= "name" > </form> if (is_uploaded_file ($_files[' myFile ' [' tmp_name '])) {$upfile = $_ files[' upload '; $name = $upfile [' name ']; $type = $upfile [' type ']; $size = $upfile [' Size ']; $tmp _name = $upfile [' Tmp_name ']; $error = $upfile [' ERROR ']; Switch ($type) {case ' image/pjpeg ': $ok =1; break} if ($ok) {move_uploaded_file ($tmp _name, ' up/'. $name);} else{echo "File type not allowed";}} 

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.