How to force mobile browser to download a .jpg
file on click from another website. so far i tried:
<a href="https://anotherwebsite.com/example.jpg" target="_blank" download>Click To Download</a>
I found two workarounds for this problem (using javascript
or php
). I use php
to bypass the problem. I create a file named download.php
with this code in it:
<?php
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (!is_null($_GET['link']) && !empty($_GET['link'])) {
$file = $_GET['link'];
try {
header('Content-type: image/*');
header("Content-Disposition: attachment; filename=\"$file\"");
readfile($file);
}
catch (Exception $ex){
echo $ex->getMessage();
}
}
}
then I change the download links to this:
<a href="download.php?link=https://anotherwebsite.com/example.jpg">Click To Download</a>
is there another way that I'm not aware of?
答案 0 :(得分:1)
此属性仅适用于同源网址。
答案 1 :(得分:1)
根据Anchor元素,此属性仅适用于同源URL。但您仍然可以使用javascript和php来解决此问题。