php文件上传基本操作
2013-01-09 11:00
525 查看
<?php /* Array ( [upload_file] => Array ( [name] => contacts1.png [type] => image/png [tmp_name] => C:\Windows\Temp\php201B.tmp [error] => 0 [size] => 132443 ) ) */ $file = $_FILES['upload_file']; /** *图片上传 *author:peng **/ //文件类型 $img_type = array('image/jpg','image/jpeg','image/png','image/pjpeg','image/gif','image/bmp','image/x-png'); //文件大小20M $max_file_size = 2000000; //文件保存目录 $upload_dir = '../upload_file/'; //判断文件类型 if(!in_array($file['type'],$img_type)){ echo "文件类型不符".$file['type']; exit; } //判断文件大小 if($file['size']>$max_file_size){ echo "文件过大"; exit; } //判断文件目录是否存在,如果不存在,则创建一个 if(!file_exists($upload_dir)){ mkdir($upload_dir); } //获取文件名:获取路径信息, $filename =$file['name']; //文件后缀名 $filetype = end(explode(".",$filename)); $newfilename = $upload_dir.date('Ymdhis',time()).rand(1000,9999).".".$filetype; //判断文件是否通过http post 的方式上传 if(!is_uploaded_file($file['tmp_name'])){ echo "文件为恶意上传"; exit; } //复制文件到指定文件夹 if(move_uploaded_file($file['tmp_name'],$newfilename)){ echo "文件上传成功"; }else{ echo "文件上传失败"; } ?>
相关文章推荐
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- PHP文件的基本操作
- 三种方法实现php网络请求(表单操作文件上传)
- php 的文件操作,上传,中常遇到的问题
- 在php中ftp上传文件到服务器的操作
- php文件上传操作
- PHP读写文件的基本操作
- 上传本地文件到github仓库基本操作
- PHP多文件上传操作
- PHP常用的基本文件和目录操作总结
- 7.27--SSH学习之SpringMVC,Ajax请求、拦截器、文件上传和MyBatis访问数据库基本操作
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- PHP文件上传操作实例详解
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- hadoop-3.0.0-beta1运维手册(007):hdfs3.0.0基本操作-上传、下载、删除文件或目录
- php文件操作基本使用方法
- cocos2dx上传文件至php服务器操作
- php课程---文件操作及文件上传的代码总结