Home > Backend Development > PHP Tutorial > 怎么实现图片下载

怎么实现图片下载

WBOY
Release: 2016-06-13 12:26:53
Original
1179 people have browsed it

如何实现图片下载
有这样一个地址 打开这个地址是图片  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');
Copy after login

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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template