Understand how php files are uploaded
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 ";
- }
- }
- ?>
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 |