php - PHP 使用文件 URL 从另一台服务器下载文件
问题描述
现在,如果我在 Chrome 的 URL 栏中粘贴相同的 URL,它会准确地下载文件。
但是当我在 ANCHOR TAG 中添加相同的 URL 时,它只会重新加载相同的页面。我已经尝试了 TARGET 属性的 _self 和 _blank 值。
这是我使用的锚标签:
<a href="url_to_file" download="link.vpf">Download File</a>
<a href="url_to_file" target="_blank">Download File</a>
<a href="url_to_file" target="_self">Download File</a>
注意: 这些锚点在 Microsoft Edge 中运行良好
此外,我为此尝试了不同的 PHP 脚本,其中一个下载了文件,但文件为空。更改不同类型文件的 URL,包括 pdf、jpg、png 和所有这些文件的文件大小为零。
$file_name = basename($vpf_url);
$fn = file_put_contents($file_name,file_get_contents($vpf_url));
header("Expires: 0");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-type: application/octet-stream");
header('Content-length: '.filesize($file_name));
header('Content-disposition: attachment; filename="'.basename($file_name).'"');
readfile($file_name);
我不知道它是跨域问题还是只是下载空文件的一些错误。
解决方案
推荐阅读
- python - Python 字符串到 shellcode 字节
- python - 如何用循环求解这个方程?
- javascript - 跟踪 Canvas 中的按键
- excel - 根据其他列中的条件汇总列中的唯一值(如果已过滤列)
- react-native - 如何在 Expo SDK 中添加应用内购买
- python - 如何模拟
.query.filter 在 Flask-SQLAlchemy - c# - 简单的 NUnit 测试失败,因为没有抛出异常(抛出测试之外)
- controls - (Progress AppBuilder) 哪个控件可以自动处理数据库浏览?
- apache-kafka - 向 Sprong Cloud DataFlow UI 公开 Kafka 属性
- javascript - 如何使用crome.js 允许用户上传他们的个人资料图片?