Understand how php files are uploaded

Source: Internet
Author: User
Understand how php files are uploaded

  1. If (is_uploaded_file ($ _ FILES ['myfile'] ['tmp _ name']) {

  2. $ Upfile = $ _ FILES ['upload'];
  3. $ Name = $ upfile ['name'];
  4. $ Type = $ upfile ['type'];
  5. $ Size = $ upfile ['size'];
  6. $ Tmp_name = $ upfile ['tmp _ name'];
  7. $ Error = $ upfile ['error'];
  8. Switch ($ type ){
  9. Case 'image/pjpeg ': $ OK = 1;
  10. Break
  11. }
  12. If ($ OK ){
  13. Move_uploaded_file ($ tmp_name, 'up/'. $ name );
  14. } Else {
  15. Echo "file type not allowed ";
  16. }
  17. }
  18. ?>

Principle analysis: // form Upload can only use multipart/form-data encoding format $ _ FILES system functions; $ _ FILES ['myfile'] ['name'] file name $ _ FILES ['myfile'] ['type'] file type, the server restricts image/** image/x-pngapplication/x-zip-compressed $ _ FILES ['myfile'] ['size'] Upload File size $ _ 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 part of the file is uploaded. 5. the size of the uploaded file is 0.

Move_uploaded_file (temporary file, target location and file name); function is_uploaded_file (MIME) for moving the file to the target location after Upload; function for determining the Uploaded MIME type File

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.