Home >Backend Development >PHP Tutorial >php下载图片解决方案

php下载图片解决方案

WBOY
WBOYOriginal
2016-06-13 12:15:13870browse

php下载图片
现在我在页面上做一个按钮,只要用户一点,我在后台用php下载指定的图片到用户的电脑上,怎么实现这个功能,不要下载到服务器上,而是直接将我直接下载图片下载到用户电脑上
------解决思路----------------------

<br /><a href="download.php">下載圖片</a><br />


download.php
<br /><?php  <br />$file = '1.jpg';  <br />if(file_exists($file)){  <br />    header('content-type:application/octet-stream');  <br />    header('content-disposition:attachment; filename='.basename($file));  <br />    header('content-length:'.filesize($file));  <br />    readfile($file);  <br />}  <br />?> <br />

Statement:
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