PHP development learning - file upload (move_uploaded_file)

WBOY
Release: 2016-07-29 09:14:25
Original
1038 people have browsed it

Function: Move the uploaded temporary files to the upload directory. Upload has been created in the root directory! ! !

Copy after login
上传文件
上传文件的文件名 $type=$upfile["type"];//上传文件的类型 $size=$upfile["size"];//上传文件的大小 $tmp_name=$upfile["tmp_name"];//上传文件的临时存放路径 //判断是否为图片 switch ($type){ case 'image/pjpeg':$okType=true; break; case 'image/jpeg':$okType=true; break; case 'image/gif':$okType=true; break; case 'image/png':$okType=true; break; } if($okType){ /** * 0:文件上传成功
* 1:超过了文件大小,在php.ini文件中设置
* 2:超过了文件的大小MAX_FILE_SIZE选项指定的值
* 3:文件只有部分被上传
* 4:没有文件被上传
* 5:上传文件大小为0 */ $error=$upfile["error"];//上传后系统返回的值 echo "================
"; echo "上传文件名称是:".$name."
"; echo "上传文件类型是:".$type."
"; echo "上传文件大小是:".$size."
"; echo "上传后系统返回的值是:".$error."
"; echo "上传文件的临时存放路径是:".$tmp_name."
"; echo "开始移动上传文件
"; //把上传的临时文件移动到upload目录下面(upload是在根目录下已经创建好的!!!) move_uploaded_file($tmp_name,"upload/".$name); $destination="upload/".$name; echo "================
"; echo "上传信息:
"; if($error==0){ echo "文件上传成功啦!"; echo "
图片预览:
"; echo "PHP development learning - file upload (move_uploaded_file)"; //echo " alt=\"图片预览:\r文件名:".$destination."\r上传时间:\">"; }elseif ($error==1){ echo "超过了文件大小,在php.ini文件中设置"; }elseif ($error==2){ echo "超过了文件的大小MAX_FILE_SIZE选项指定的值"; }elseif ($error==3){ echo "文件只有部分被上传"; }elseif ($error==4){ echo "没有文件被上传"; }else{ echo "上传文件大小为0"; } }else{ echo "请上传jpg,gif,png等格式的图片!"; } } ?>

Execution result:

PHP development learning - file upload (move_uploaded_file)

The above introduces PHP development and learning - file upload (move_uploaded_file), including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!