PHP file uploadThe principle is simply analyzed. Friends who learn PHP can refer to it. It is indeed much simpler than asp.
//Form uploads can only use the multipart/form-data encoding format
$_FILES system Function ;
$_FILES['myFile']['name'] file Name
$_FILES['myFile']['type']The type of file, restricted by the server
image/**
image/x-png
application/x-zip-compressed
$_FILES['myFile']['size']Upload file size
$_FILES['myFile']['tmp_name']Save the temporary file name after uploading to the service
$_FILES['myFile'][ 'error'] Error code;
0 Success 1 Exceeds the php.ini size 2 Exceeds the value specified by the MAX_FILE_SIZE option
3 Only partially uploaded 5 The uploaded file size is 0
move_uploaded_file(temporary file, target location and file name);
Function to move the file to the target location after uploading
is_uploaded_file(MIME);
Function to determine the uploaded MIME type of the file
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 "文件类型不允许"; } }
The above is the detailed content of A brief introduction to the principle of php file upload. For more information, please follow other related articles on the PHP Chinese website!