PHP实现原生态图片上传封装类方法
php  /  管理员 发布于 7年前   129
PHP图片上传类,经典方式,不过上传效率还算可以,我自己用过的一个类,当时对这个类做了些修改,以满足自己特定功能的需要,对PHP熟悉的,可对这个上传类做优化和修改,后附有调用方法,让PHP开发者上传图片轻松容易就做到,先上类代码: 以下是PHP上传类的调用方法,PHP代码如下: 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。 GetFileAttri() ){ $pass = false;}if( ! $this -> CheckFileMIMEType() ) { $pass = false; $this -> error .= die("");}if( ! $this -> CheckFileAttri_size() ){ $pass = false; $this -> error .= die(""); return false;}if ( ! $this -> MoveFileToNewPath() ){ $pass = false; $this -> error .= die("");} return $pass;}function GetFileAttri(){ foreach( $_FILES as $tmp ) { $this -> uploadFile = $tmp; } return (empty( $this -> uploadFile[ 'name' ])) ? false : true;}function CheckFileAttri_size(){ if ( ! empty ( $this -> fileSize )) { if ( is_numeric( $this -> fileSize )) { if ($this -> fileSize > 0) { return ($this -> uploadFile[ 'size' ] > $this -> fileSize * 1024) ? false : true ; } } else { return false; } } else { return false; } } function ChangeFileName ($prefix = NULL , $mode) {// string $prefix , int $mode $fullName = (isset($prefix)) ? $prefix."_" : NULL ; switch ($mode) { case 0 : $fullName .= rand( 0 , 100 ). "_" .strtolower(date ("ldSfFYhisa")) ; break; case 1 : $fullName .= rand( 0 , 100 ). "_" .time(); break; case 2 : $fullName .= rand( 0 , 10000 ) . time(); break; default : $fullName .= rand( 0 , 10000 ) . time(); break; } return $fullName; } function MoveFileToNewPath() { $newFileName = NULL; $newFileName = $this -> ChangeFileName( $this -> filePrefix , 2 ). "." . $this -> GetFileTypeToString(); //检查目录是否存在,不存在则创建,当时我用的时候添加了这个功能,觉得没用的就注释掉吧 /* $isFile = file_exists( $this -> accessPath); clearstatcache(); if( ! $isFile && !is_dir($this -> accessPath) ) { echo $this -> accessPath; @mkdir($this -> accessPath); }*/$array_dir=explode("/",$this -> accessPath);//把多级目录分别放到数组中 for($i=0;$i
accessPath ='upload';//图片上传的目录,这里是当前目录下的upload目录,可自己修改 if ( $tmp -> TODO() ) { $filename=$tmp -> newFileName;//生成的文件名 echo "图片上传成功,路径为:upload/".$filename; }else{ echo $tmp -> error; } }else{ echo "没有图片数据可上传";}?>
您可能感兴趣的文章:
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号