Home > Backend Development > PHP Tutorial > PHP文件上传原理简单分析_PHP

PHP文件上传原理简单分析_PHP

WBOY
Release: 2016-06-01 12:16:52
Original
799 people have browsed it

//表单上传只能使用multipart/form-data编码格式
$_FILES系统函数;
$_FILES['myFile']['name']文件名称
$_FILES['myFile']['type']文件的类型,服务端进行限制
image/**
image/x-png
application/x-zip-compressed
$_FILES['myFile']['size']上传文件大小
$_FILES['myFile']['tmp_name']上传服务后保存临时文件名
$_FILES['myFile']['error']错误代码;
0成功1超过php.ini大小2超过MAX_FILE_SIZE选项指定的值
3只有部分上传 5上传文件大小为0

move_uploaded_file(临时文件,目标位置和文件名);
上传后移动文件到目标位置的函数
is_uploaded_file(MIME);
判断上传MIME类型的文件函数
复制代码 代码如下:




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 "文件类型不允许";
}
}
Related labels:
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