PHP File Upload principle simple analysis _php skill

Source: Internet
Author: User
Form uploads can only use the Multipart/form-data encoding format
$_files system function;
$_files[' myFile ' [' name '] file name
$_files[' myFile ' [' type '] file types, server-side restrictions
image/**
Image/x-png
Application/x-zip-compressed
$_files[' myFile ' [' Size '] upload file size
$_files[' myFile ' [' tmp_name '] store temporary file name after uploading service
$_files[' myFile ' [' ERROR '] error code;
0 Success 1 exceeds php.ini size 2 exceeds the value specified by the max_file_size option
3 only partial upload 5 upload file size is 0

Move_uploaded_file (temporary file, target location and filename);
A function to move a file to a target location after uploading
Is_uploaded_file (MIME);
To determine file functions for uploading MIME types
Copy Code code 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.