本文介绍了如何使像pdf文件一样的jpg图像下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个请求,以与pdf文件相同的方式下载jpg图像。
I have a request to make a jpg image download in the same way a pdf file would.
目前,如果我将jpg图像添加到网页中一个链接,它将在另一个浏览器窗口中打开,而不是实际下载到用户计算机。但是,一个pdf文件将。
At present if I add a jpg image to a web page as a link, it will open in another browser window rather than actually download to the users computer. However, a pdf file will.
这是标准代码:
<a href="/images/my-image.jpg">download image</a>感谢任何关于此的指导。
I would appreciate any guidance on this.
谢谢。
推荐答案如果您在服务器上有PHP,可以这样做。
If you have PHP on the server you can do this.
<?php // Force download of image file specified in URL query string and which // is in the same directory as this script: if(!empty($_GET['img'])) { $filename = basename($_GET['img']); // don't accept other directories $size = @getimagesize($filename); $fp = @fopen($filename, "rb"); if ($size && $fp) { header("Content-type: {$size['mime']}"); header("Content-Length: " . filesize($filename)); header("Content-Disposition: attachment; filename=$filename"); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); fpassthru($fp); exit; } } header("HTTP/1.0 404 Not Found"); ?>HTML然后看起来像这样
HTML Would then look like this
<img src="/images/download.php?img=imagename.jpg" alt="test">更多推荐
如何使像pdf文件一样的jpg图像下载?
发布评论