为什么上传图片中含有透明通道,图片就会变成黑色?
p.s. 改的图片上传类原文地址:http://blog.csdn.net/a957651480/article/details/23124257
<?php <br /><br>class Images{<br><br> var $inputName; //控件名<br> var $allowType = array(<br> 'image/gif','image/jpg','image/jpeg','image/png','image/x-png','image/pjpeg'<br> ); //上传类型<br> var $allowSize = 1048576; //限制大小<br> var $saveDir = ""; //保存目录<br> var $FileName = ""; //文件名<br> var $isRename = false; //是否重命名,默认为true<br> var $errID = 0; //错误代码,默认为0<br> var $errMsg = ""; //错误信息<br> var $savePath = ""; //保存路径<br> var $ImgSize = 0; //图片尺寸<br><br> function __construct($inputName,$allowType="",$allowSize="",$saveDir="",$isRename=true){<br> if(empty($inputName)){<br> $this->chk_err(-1); //无传入控件名<br> }else{<br> $this->inputName = $inputName;<br> }<br><br> if(!empty($allowType)) $this->allowType = $allowType;<br> if(!empty($allowSize)) $this->allowSize = $allowSize;<br> if(!empty($saveDir)) $this->saveDir = $saveDir;<br> if(!empty($isRename)) $this->isRename = $isRename;<br> }<br><br> function is_uploaded(){<br> if(empty($_FILES[$this->inputName]['name'])){<br> $this->chk_err(4); //没有文件被上传<br> }else{<br> if(is_uploaded_file($_FILES[$this->inputName]['tmp_name'])){<br> return true;<br> }else{<br> $this->chk_err(-2); //文件上传不合法<br> }<br> }<br> }<br><br> function chk_type(){<br> if(!in_array($_FILES[$this->inputName]['type'],$this->allowType)){<br> $this->chk_err(-3); //上传的文件类型不被允许<br> }else{<br> return true;<br> }<br> }<br><br> function chk_size(){<br> if($_FILES[$this->inputName]['size'] > $this->allowSize){<br> $this->chk_err(-4); //上传的文件过大<br> }else{<br> return true;<br> }<br> }<br><br> function move_uploaded(){ //移动上传文件<br> if(!$this->is_uploaded()){<br> return false;<br> }<br><br> if(!$this->chk_size()){<br> return false;<br> }<br><br> if(!$this->chk_type()){<br> return false;<br> }<br><br> //重命名<br> if($this->isRename){<br> $arrTmp = pathinfo($_FILES[$this->inputName]['name']);<br> $extension = strtolower($arrTmp['extension']);<br> $file_newname = $this->FileName; //重命名新文件<br> }else{<br> $file_newname = $_FILES[$this->inputName]['name'];<br> }<br> <br> if(!file_exists($this->saveDir)){ //判断保存目录是否存在<br> mkdir($this->saveDir,0777,true); //建立保存目录<br> }<br><br> //移动文件<br> $result = move_uploaded_file($_FILES[$this->inputName]['tmp_name'],$this->saveDir."/".$file_newname);<br><br> if($result){<br> $path = $this->savePath = $this->saveDir."/".$file_newname; //文件的成功保存路径<br> return $path;<br> }else{<br> $this->chk_err($_FILES[$this->inputName]['error']);<br> }<br> <br> }<br><br> //判断出错信息<br> function chk_err($errID){<br> $this->errID = $errID;<br><br> switch($this->errID){<br> case -4:<br> $this->errMsg = '只能上传1M以内的图片 | <a>[返回]</a>';<br> break;<br> case -3:<br> $this->errMsg = '这不是一张图片 | <a>[返回]</a>';<br> break;<br> case -2:<br> $this->errMsg = '文件上传不合法 | <a>[返回]</a>';<br> break;<br> case -1:<br> $this->errMsg = '无控件名传入 | <a>[返回]</a>';<br> break;<br> case 1:<br> $this->errMsg = '上传的文件超出了php.ini中upload_max_filesize设定的最大值 | <a>[返回]</a>';<br> break;<br> case 2:<br> $this->errMsg = '上传文件的大小超过了HTML表单中MAX_FILE_SIZE选项指定的值 | <a>[返回]</a>';<br> break;<br> case 3:<br> $this->errMsg = '文件只有部分被上传 | <a>[返回]</a>';<br> break;<br> case 4:<br> $this->errMsg = '请选择一张图片 | <a>[返回]</a>';<br> break;<br> default:<br> break;<br> }<br> return false;<br> <br> }<br><br> function get_errMsg(){<div class="clear"> </div>