我有一个示例代码:
使用imageData=iVBORw0KGgoAAAANS...AAAAAElFTkSuQmCC发布数据
$imgData = $_REQUEST['imageData'];
$data = base64_decode($imgData);
$im = imagecreatefromstring($data);
if($im !== false) {
header('Content-Type: image/png');
imagepng($im, 'test.png');
imagedestroy($im);
echo 'Success !!!';
} else {
echo 'Failer ???';
}如何将图片保存到我的电脑,而不是保存到网站?
发布于 2013-10-30 10:58:17
如果您这样做了:
imagepng($im, 'test.png');您将告诉imagepng()生成一个png文件,并使用您提供的名称保存它。
如果你这样做了:
imagepng($im);它将生成的PNG图像输出(发送到客户端)。
您基本上只需要这样,并删除echo,您不应该发送图像数据的任何东西。
如果您想要强制下载,请使用:
header('Content-Type: image/png');
header('Content-Disposition: attachment; filename="downloadme.png"');
imagepng($im);发布于 2013-10-30 11:02:41
如何将图像保存到我的电脑中,而不是保存在网站中?
使用标题提示下载。
<?php
$imgData = $_REQUEST['imageData'];
$data = base64_decode($imgData);
$im = imagecreatefromstring($data);
if($im !== false) {
// set the headers, to trigger a download
header("Pragma: public");
header("Expires: -1");
header("Cache-Control: public, must-revalidate, post-check=0, pre-check=0");
header('Content-Disposition: attachment; filename="image.png"');
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
} else {
echo 'Failer ???';
}
?>https://stackoverflow.com/questions/19673009
复制相似问题