Home  >  Article  >  Backend Development  >  PHP文件上传原理简单分析_php技巧

PHP文件上传原理简单分析_php技巧

WBOY
WBOYOriginal
2016-05-17 09:18:59752browse

//表单上传只能使用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 "文件类型不允许";
}
}
Statement:
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