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...