Simple analysis of PHP file upload principle_PHP tutorial

WBOY
Release: 2016-07-21 15:29:10
Original
964 people have browsed it

//Form uploads can only use the multipart/form-data encoding format
$_FILES system function;
$_FILES['myFile']['name']File name
$_FILES['myFile'][ 'type'] file type, restricted by the 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 Exceeds the value specified by the MAX_FILE_SIZE option
3 Only partially uploaded 5 Uploaded file size is 0

move_uploaded_file (temporary file, target location and file name);
Moved after upload The function that files to the target location
is_uploaded_file(MIME);
The file function that determines the uploaded MIME type

Copy the code 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";
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323464.htmlTechArticle//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, the server limits it...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template