简体   繁体   English

带有下载图片按钮的灯箱

[英]Lightbox with download image button

I'm trying to add a "download image" button to my lightbox. 我正在尝试向灯箱添加“下载图片”按钮。 Therefore I'm going to add a simple button to this lightbox: http://lokeshdhakar.com/projects/lightbox2/ 因此,我将向此灯箱添加一个简单的按钮: http : //lokeshdhakar.com/projects/lightbox2/

I already tried the HTML5 download attribute but it's not suitable because it's not browser compatible. 我已经尝试过HTML5下载属性,但由于它与浏览器不兼容,因此不适合使用。

Right click -> "save as..." is also not a solution, because the controls of the lightbox are on top of the image. 右键单击->“另存为...”也不是解决方案,因为灯箱的控件位于图像顶部。

Is there a simple cross browser compatible solution to add a download button to the lightbox? 是否有一个简单的跨浏览器兼容解决方案,可以向灯箱添加下载按钮? I've also tried to use Blob or BlobBuilder but wasn't successful. 我也尝试过使用Blob或BlobBuilder,但没有成功。 Is this the right approach? 这是正确的方法吗?

Edit: 编辑:

I've found a working solution here: https://stackoverflow.com/a/833024/1301058 我在这里找到了可行的解决方案: https : //stackoverflow.com/a/833024/1301058

<FilesMatch "\.jpg$">
<IfModule mod_headers.c>
Header set Content-Disposition "attachment"
# for older browsers
Header set Content-Type "application/octet-stream"
</IfModule>
</FilesMatch>

But the problem is, that all images are transferred with MIME type application/octet-stream and I receive warnings for that. 但是问题是,所有图像都以MIME类型application / octet-stream传输,我收到警告。

How can I set the mimetype on click? 如何在点击时设置模仿类型? I tried to add a parameter to the file path and the FilesMatch regex like: 我试图将参数添加到文件路径和FilesMatch正则表达式中,例如:

<FilesMatch "\.jpg\?1$">

But that doesn't work. 但这是行不通的。

add button that calls .php file with code like this. 添加使用以下代码调用.php文件的按钮。

<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');

// The PDF source is in original.pdf
readfile('original.pdf');
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM