<?php
$fileinfo=$_FILES["myfile"];
function uploadfile($fileinfo,$allowext=array('jpeg','jpg','pnd','gif','wbmp'),$flag=true,$maxsize=2097152){
//判断错误信息
if($fileinfo['error']>0)
{
switch($fileinfo['error'])
{
case 1:
$mes= "上传文件超过了PHP配置文件中upload_max_filesize选项的值";
break;
case 2:
$mes= "超过了表单MAX_FILE_SIZE的限制大小";
break;
case 3:
$mes= "文件部分被上传";
break;
case 4:
$mes= "没有选择上传文件";
break;
case 6:
$mes= "没有找到临时目录";
break;
case 7:
case 8:
$mes= "系统错误";
break; }
exit($mes); } //判断上传文件类型是不是在规定类型中
$allowext=array('jpeg','jpg','pnd','gif','wbmp'); //定义一下允许的上传文件类型
$ext=strtolower(end(explode(',',$fileinfo['name'])));//截取上传文件扩展名
if(!in_array($ext,$allowext)) // 判断上传文件的扩展名是不是在定义类型中
{
exit('非法文件类型');
} //判断上传文件大小
$maxsize=2097152; //写最大的字节数,自己算
if($fileinfo['size']>$maxsize)
{
exit('上传文件过大');
} //判断文件是否是通过HTTP POST方式上传上来的
if(!is_uploaded_file($fileinfo['tmp_name']))
{
exit('文件不是通过HTTP POST方式上传上来的');
} //检测是否为真实的图片类型,而不是认为改动的
$flag=true;
if($flag)
{
if(!getimagesize($fileinfo['tmp_name']))
{
echo "不是真实的图片类型";
}
} //判断服务器上存储的文件夹在不在
$path='uploads'; //服务器上存储文件的文件名
if(!file_exists($path))
{
mkdir($path,0777,true);//不存在就创建一个目录
chmod($path,0777);//加一个权限 }
$uniname=md5(uniqid(microtime(true),true)).'.'.$ext; //通过MD5加密等措施给文件名取名,产生唯一文件名 $destination=$path.'/'.$uniname;
if(!move_uploaded_file($fileinfo['tmp_name'],$destination)) //上传文件
{
echo "文件上传失败";
} return array( 'newname'=>$destination,
'size'=>$fileinfo['size'],
'type'=>$fileinfo['type'] ); }

最新文章

  1. Oracle update和order by
  2. 虚拟机中Linux系统盘空间不足
  3. [转]架构蓝图--软件架构 &quot;4+1&quot; 视图模型
  4. 常用mysql数据库引擎——MyISAM和InnoDB区别
  5. 数据库知识整理&lt;三&gt;
  6. Oracle数据库——触发器的创建与应用
  7. Android开发环境的安装 Eclipse
  8. commons-lang3-3.4.jar
  9. Inside of Jemalloc
  10. SQLite入门与分析(八)---存储模型(3)
  11. JAVA 时间差距,两个时间相差多少天,时,分,秒
  12. Bzoj 4408: [Fjoi 2016]神秘数 可持久化线段树,神题
  13. CodeForces 135C C. Zero-One
  14. Jenkins 发布后自动创建git tag
  15. 使用VS Code开发调试.NET Core 2.0
  16. 一起学Android之GridView
  17. element-UI——el-table添加序号
  18. linux下生成00 01 02..99的这些数
  19. C#隐藏手机号中间四位为*
  20. django 环境配置.

热门文章

  1. iOS autoresizing布局
  2. 如果Python中有很多换行,可以选择使用&quot;&quot;&quot;...&quot;&quot;&quot;表示多行内容
  3. Windows 10 RTM 官方正式版
  4. Servlet入门
  5. 关于ajax跨域请求(cross Domain)
  6. SPRING 标签库
  7. 到入百度LSS framework Reason: image not found
  8. popen使用不当引起产生僵尸进程
  9. SQL GROUP BY 中的TOP N
  10. Thinkphp模型问题(一)