Home >Backend Development >PHP Tutorial >php click link image download program code

php click link image download program code

不言
不言Original
2018-04-14 15:36:452717browse

这篇文章主要介绍了php 点击链接图片下载程序代码 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

	页面用<a href>click</a>跳转进来,就可以直接下载文件了
<br/>
	$imageName = $_GET[&#39;imageName&#39;];
	$imageUrl = $_GET[&#39;imageUrl&#39;];
	
	$localhostPath = str_replace("\\","/",dirname(__FILE__));  //这里要引用绝对路径
	$imageUrl = $localhostPath."/".$imageUrl."/".$imageName;   //合并成一个完整的路径
	$imageUrl = iconv(&#39;utf-8&#39;, &#39;gbk&#39;, $imageUrl);              //这里可以防止中文名文件乱码,我的机器环境是utf-8
	
	header(&#39;Content-type: application/octet-stream&#39;);
	header(&#39;Content-Disposition: attachment; filename=&#39;.$filename); 
	header("Content-Length:". filesize($imageName));  
	
	ob_clean();
	flush();
	readfile($imageUrl);



The above is the detailed content of php click link image download program code. For more information, please follow other related articles on the PHP Chinese website!

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