php用gd库生成图片后下载问题
是这样的,我在用GD库生成图片后,不保存图片能直接下载吗? 试了一个早上还是不行…
image.php
//创建一个真彩画布<br /> $image = imagecreatetruecolor(400,190);<br /> //背景创建颜色<br /> $green = imagecolorallocate($image,255,255,255);<br /> //填充画布颜色<br /> imagefill($image,0,0,$green);<br /> //输出图片<br /> header("Content-Type: image/jpeg");<br /> imagejpeg($image);<br /> //销毁资源<br /> imagedestroy($image);
<a href="imagedown.php?filename=image.php"><img src="image.php" / alt=" php用gd库生成图片后上载有关问题 " ></a>
<br /> if(isset($_GET['filename'])){<br /> ????????//var_dump(getimagesize($_GET['filename']));<br /> ????????download($_GET['filename']);<br /> ????}<br /> ????function download($fileName){<br /> ????????header("Content-Type: image/jpeg");<br /> ????????header('Content-Disposition: attachment; filename="'.$fileName.'"');<br /> ????????header('Content-Length: '.filesize($fileName));<br /> ????????readfile($fileName);<br /> ????}<br />
download('x.jpg');<br /> <br /> function image() {<br /> //创建一个真彩画布<br /> $image = imagecreatetruecolor(400,190);<br /> //背景创建颜色<br /> $green = imagecolorallocate($image,255,255,0);<br /> //填充画布颜色<br /> imagefill($image,0,0,$green);<br /> //输出图片<br /> //header("Content-Type: image/jpeg");<br /> imagejpeg($image);<br /> //销毁资源<br /> imagedestroy($image);<br /> }<br /> <br /> function download($fileName){<br /> ob_start();<br /> image();<br /> $s = ob_get_clean();<br /> header("Content-Type: image/jpeg");<br /> header('Content-Disposition: attachment; filename="'.$fileName.'"');<br /> header('Content-Length: '.strlen($s));<br /> echo $s;<br /> }