Simple analysis of PHP file uploading principles _ PHP Tutorial

Source: Internet
Author: User
Simple analysis of PHP file uploading principles. Form Upload can only use the multipartform-data encoding format $ _ FILES system functions; $ _ FILES [myFile] [name] file name $ _ FILES [myFile] [type] file type, restrictions on the server // only multipart/form-data encoding formats can be used for form Upload
$ _ FILES system functions;
$ _ FILES ['myfile'] ['name'] file name
$ _ FILES ['myfile'] ['type'] specifies the file type, which is restricted by the server.
Image /**
Image/x-png
Application/x-zip-compressed
$ _ FILES ['myfile'] ['size'] size of the uploaded file
$ _ FILES ['myfile'] ['tmp _ name'] Save the temporary file name after uploading the 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 partially uploaded 5. the size of the uploaded file is 0.

Move_uploaded_file (temporary file, target location and file name );
Function for moving the uploaded file to the target location
Is_uploaded_file (MIME );
Function used to determine the upload MIME type

The code is as follows:



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 ";
}
}

Functions $ _ FILES system functions; $ _ FILES ['myfile'] ['name'] file name $ _ FILES ['myfile'] ['type'] file type, restrictions on the server...

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.