




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
setSavepath($savePath);$this-setFileformat($fileFormat);$this-setMaxsize($maxSize);$this-setOverwrite($overwrite);$this-setThumb($this-thumb, $this-thumbWidth,$this-thumbHeight);$this-errno = 0;/ 上传/ param $fileInput 网页Form(表单)中input的名称/ param $changeName 是否更改文件名function run($fileInput,$changeName = 1)if(isset($_FILES$fileInput)$fileArr = $_FILES$fileInput;if(is_array($fileArrname)/上传同文件域名称多个文件for($i = 0; $i getExt($arname);/取得扩展名,赋给$this-ext,下次循环会更新$this-setSavename($changeName = 1 ? : $arname);/设置保存文件名if($this-copyfile($ar)$this-returnArray = $this-returninfo;else$this-returninfoerror = $this-errmsg();$this-returnArray = $this-returninfo;return $this-errno ? false : true;else/上传单个文件$this-getExt($fileArrname);/取得扩展名$this-setSavename($changeName = 1 ? : $fileArrname);/设置保存文件名if($this-copyfile($fileArr)$this-returnArray = $this-returninfo;else$this-returninfoerror = $this-errmsg();$this-returnArray = $this-returninfo;return $this-errno ? false : true;return false;else$this-errno = 10;return false;/ 单个文件上传/ param $fileArray 文件信息数组function copyfile($fileArray)$this-returninfo = array();/ 返回信息$this-returninfoname = $fileArrayname;$this-returninfosaveName = $this-saveName;$this-returninfosize = number_format( ($fileArraysize)/1024 , 0, ., );/以KB为单位$this-returninfotype = $fileArraytype;/ 检查文件格式if (!$this-validateFormat()$this-errno = 11;return false;/ 检查目录是否可写if(!is_writable($this-savePath)$this-errno = 12;return false;/ 如果不允许覆盖,检查文件是否已经存在if($this-overwrite = 0 & file_exists($this-savePath.$fileArrayname)$this-errno = 13;return false;/ 如果有大小限制,检查文件是否超过限制if ($this-maxSize != 0 )if ($fileArraysize $this-maxSize)$this-errno = 14;return false;/ 文件上传if(!copy($fileArraytmp_name, $this-savePath.$this-saveName)$this-errno = $fileArrayerror;return false;elseif( $this-thumb )/ 创建缩略图$CreateFunction = imagecreatefrom.($this-ext = jpg ? jpeg : $this-ext);$SaveFunction = image.($this-ext = jpg ? jpeg : $this-ext);if (strtolower($CreateFunction) = imagecreatefromgif & !function_exists(imagecreatefromgif) $this-errno = 16;return false; elseif (strtolower($CreateFunction) = imagecreatefromjpeg & !function_exists(imagecreatefromjpeg) $this-errno = 17;return false; elseif (!function_exists($CreateFunction) $this-errno = 18;return false;$Original = $CreateFunction($this-savePath.$this-saveName);if (!$Original) $this-errno = 19; return false;$originalHeight = ImageSY($Original);$originalWidth = ImageSX($Original);$this-returninfooriginalHeight = $originalHeight;$this-returninfooriginalWidth = $originalWidth;if ($originalHeight thumbHeight & $originalWidth thumbWidth) / 如果比期望的缩略图小,那只Copycopy($this-savePath.$this-saveName, $this-savePath.$this-thumbPrefix.$this-saveName); else if( $originalWidth $this-thumbWidth )/ 宽 设定宽度$thumbWidth = $this-thumbWidth ;$thumbHeight = $this-thumbWidth * ( $originalHeight / $originalWidth );if($thumbHeight $this-thumbHeight)/ 高 设定高度$thumbWidth = $this-thumbHeight * ( $thumbWidth / $thumbHeight );$thumbHeight = $this-thumbHeight ;elseif( $originalHeight $this-thumbHeight )/ 高 设定高度$thumbHeight = $this-thumbHeight ;$thumbWidth = $this-thumbHeight * ( $originalWidth / $originalHeight );if($thumbWidth $this-thumbWidth)/ 宽 设定宽度$thumbHeight = $this-thumbWidth * ( $thumbHeight / $thumbWidth );$thumbWidth = $this-thumbWidth ;if ($thumbWidth = 0) $thumbWidth = 1;if ($thumbHeight = 0) $thumbHeight = 1;$createdThumb = imagecreatetruecolor($thumbWidth, $thumbHeight);if ( !$createdThumb ) $this-errno = 20; return false;if ( !imagecopyresampled($createdThumb, $Original, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $originalWidth, $originalHeight) )$this-errno = 21; return false;if ( !$SaveFunction($createdThumb, $this-savePath.$this-thumbPrefix.$this-saveName) )$this-errno = 22; return false;/ 删除临时文件if(!$this-del($fileArraytmp_name)return false;return true;/ 文件格式检查,MIME检测function validateFormat()if(!is_array($this-fileFormat) | in_array(strtolower($this-ext), $this-fileFormat) | in_array(strtolower($this-returninfotype), $this-fileFormat) )return true;elsereturn false;/ 获取文件扩展名/ param $fileName 上传文件的原文件名function getExt($fileName)$ext = explode(., $fileName);$ext = $extcount($ext) - 1;$this-ext = strtolower($ext);/ 设置上传文件的最大字节限制/ param $maxSize 文件大小(bytes) 0:表示无限制function setMaxsize($maxSize)$this-maxSize = $maxSize;/ 设置文件格式限定/ param $fileFormat 文件格式数组function setFileformat($fileFormat)if(is_array($fileFormat)$this-fileFormat = $fileFormat ;/ 设置覆盖模式/ param overwrite 覆盖模式 1:允许覆盖 0:禁止覆盖function setOverwrite($overwrite)$this-overwrite = $overwrite;/ 设置保存路径/ param $savePath 文件保存路径:以 / 结尾,若没有 /,则补上function setSavepath($savePath)$this-savePath = substr( str_replace(,/, $savePath) , -1) = / ? $savePath : $savePath./;/ 设置缩略图/ param $thumb = 1 产生缩略图 $thumbWidth,$thumbHeight 是缩略图的宽和高function setThumb($thumb, $thumbWidth = 0,$thumbHeight = 0)$this-thumb = $thumb;if($thumbWidth) $this-thumbWidth = $thumbWidth;if($thumbHeight) $this-thumbHeight = $thumbHeight;/ 设置文件保存名/ param $saveName 保存名,如果为空,则系统自动生成一个随机的文件名function setSavename($saveName)if ($saveName = ) / 如果未设置文件名,则生成一个随机文件名$name = date(YmdHis)._.rand(100,999).$this-ext; else $name = $saveName;$this-saveName = $name;/ 删除文件/ param $fileName 所要删除的文件名function del($fileName)if(!unlink($fileName)$this-errno = 15;return false;return true;/ 返回上传文件的信息function getInfo()return $this-returnArray;/ 得到错误信息function errmsg()$uploadClassError = array(0=There is no error, the file uploaded with success. ,1=The uploaded file exceeds the upload_max_filesize directive in php.ini.,2=The uploaded file exceeds the MAX_FILE_SIZE that was specified in the HTML form.,3=The uploaded file was only partially uploaded. ,4=No file was uploaded. ,6=Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3. ,7=Failed to write file to disk. Introduced in PHP 5.1.0. ,10=Input name is not unavailable!,11=The uploaded file is Unallowable!,12=Directory unwritable!,13=File exist already!,14=File is too big!,15=Delete file unsuccessfully!,16=Your version of PHP does not appear to have GIF thumbnailing support.,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年不动产登记代理人考试复习指南与模拟题
- 护理出科试题及答案解析
- 母婴护理考试题目及答案
- 2025年乡村兽医登记考试知识点总结与回顾
- 中西医结合外科学(副高)2025年考试试题及答案
- 2025年市场营销师职业资格认证模拟题及答案
- 2025年健身教练专业考试模拟题集及解析
- 2025年医疗机构护士员招聘考试题库及参考答案
- 2025年名企招聘面试模拟题详解及备考指南
- 工地挖掘机租用合同4篇
- 2025年国家保安员资格考试模拟100题及答案
- 防火公路施工方案
- 商学院课程总结与展望
- 《集中用餐单位落实食品安全主体责任监督管理规定》解读与培训
- 2025年(幼儿园)教师资格考试《保教知识与能力》模拟测试题及答案(共三套)
- 物业管理服务项目进度保证措施
- GB/T 10810.1-2025眼镜镜片第1部分:单焦和多焦
- GB/T 45265-2025下肢假肢增材制造通用技术要求
- 足球比赛裁判培训
- 2025年职工职业技能竞赛(制图员赛项)参考试题库(含答案)
- 胖东来管理制度
评论
0/150
提交评论