使用类似代码上传的'png''bmp'图像无法像'jpeg''gif'图像一样正确上传

时间:2017-02-13 04:35:42

标签: php image gd

我的程序使用以下代码与jpeg和gif图像完美配合。但是,当我尝试上传png和bmp文件时,图像无法正常上传。我做错了什么?

list($width,$height)=getimagesize($imagefile);

if($_FILES['image']['type']=="image/png"){$src=imagecreatefrompng($imagefile);$type="png";}             
if($_FILES['image']['type']=="image/gif"){$src=imagecreatefromgif($imagefile);$type="gif";} 
if($_FILES['image']['type']=="image/bmp"){$src=imagecreatefromwbmp($imagefile);$type="bmp";}
if($_FILES['image']['type']=="image/jpeg"){$src=imagecreatefromjpeg($imagefile);$type="jpeg";}

$orig_h=($height/$width)* $orig_w;          
$tmp=imagecreatetruecolor($orig_w,$orig_h);
imagecopyresampled($tmp,$src,0,0,0,0,$orig_w,$orig_h,$width,$height);
imagejpeg($tmp,$folder.$filename,100);


if($type=="png"){imagepng($tmp,$folder.$filename,100);}         
if($type=="gif"){imagegif($tmp,$folder.$filename,100);} 
if($type=="bmp"){imagewbmp($tmp,$folder.$filename,100);}
if($type=="jpeg"){imagejpeg($tmp,$folder.$filename,100);}

imagedestroy($tmp);
imagedestroy($src);

0 个答案:

没有答案