PHP File Upload principle simple analysis, learning PHP friends can refer to, indeed more than the ASP is much simpler.
Form uploads can only be used in MULTIPART/FORM-DATA encoded format
$_files system functions;
$_files[' myFile ' [' name '] file name
$_files[' myFile ' [' type '] file types, limited by server
image/**
Image/x-png
Application/x-zip-compressed
$_files[' myFile ' [' Size '] upload file size
$_files[' myFile ' [' tmp_name '] save temporary file name after uploading service
$_files[' myFile ' [' ERROR '] error code;
0 Success 1 exceeds php.ini size 2 value specified by Max_file_size option
3 only partially uploaded 5 upload file size is 0
Move_uploaded_file (temporary file, target location and file name);
Functions for moving files to the target location after uploading
Is_uploaded_file (MIME);
To determine the file function of the upload MIME type
The code is 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";}}