当前位置:Gxlcms > PHP教程 > 怎么实现图片下载

怎么实现图片下载

时间:2021-07-01 10:21:17 帮助过:19人阅读

如何实现图片下载
有这样一个地址 打开这个地址是图片 http://qr.topscan.com/api.php?text=x
想实现这样的一个功能
1.html

点击下载图片

1.php

$filename= http://qr.topscan.com/api.php?text=x
header('Content-type: image/jpeg');
header("Content-Disposition: attachment; filename='$filename'");


这样没办法下载图片,请教一下大家应该怎么写



------解决思路----------------------
不明白你们在干什么?
点击下载图片
如果是为了显示图片,则 1.php 为
echo file_get_contents('http://qr.topscan.com/api.php?text=x');

如果是为了下载图片,则 1.php 为
$s = file_get_contents('http://qr.topscan.com/api.php?text=x');
Header("Content-type: application/force-download");
Header("Accept-Ranges:bytes");
Header("Accept-Length:" . strlen($s));
Header("Content-Disposition: attachment; filename=x.png");
echo $s;

file_exists 函数只用于检查本地文件是否存在

人气教程排行