您好,您不能使用纯 html 下载属性来做到这一点。
我看不清楚我们如何用js做到这一点。
对于php解决方案,您需要卷曲您的图像的url并将图像以相同的域名放在您的服务器中,然后您可以使用下载属性并且它会起作用
编辑:
对于 php 版本,我可以是:
您需要先创建一个files/ 文件夹
<?php
function grab_image($url,$saveto){
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // <-- don't forget this
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // <-- and this
$raw=curl_exec($ch);
curl_close ($ch);
if(file_exists($saveto)){
unlink($saveto);
}
$fp = fopen($saveto,'x');
fwrite($fp, $raw);
fclose($fp);
}
$link = "https://images-na.ssl-images-amazon.com/images/I/81tISKde7HL._AC_SL1500_.jpg"; // your link
$temp_match;
preg_match('/(?=\w+\.\w{3,4}$).+/',$link,$temp_match); // get the filename from url return an array
$file_name = $temp_match[0]; //get the name from the array
$path= ('./files/'.$file_name); // create path
grab_image($link,$path);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<a href="<?= $path ?>" download="<?=$file_name?>">download</a>
</body>
</html>