【问题标题】:How to hide a download link如何隐藏下载链接
【发布时间】:2013-07-26 05:17:01
【问题描述】:

我有一个 PHP 脚本,它应该允许用户在不显示 URL 的情况下下载文件。当我尝试以下内容时,我下载的文件是空的。有人可以帮忙吗?

<?php
$file_name = 'test.exe';
$file_url = 'https://www.example.com/' . $file_name;
header('Content-Type: application/octet-stream');
header("Content-disposition: attachment; filename=".$file_name); 
readfile($file_url);
?>

【问题讨论】:

标签: php url download


【解决方案1】:

你应该这样使用

header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: Binary")
header("Content-disposition: attachment; filename=\"file.exe\""); 
echo readfile($url);

还有基于您的文件应用程序/zip、应用程序/pdf 等的内容类型

AND 或更好的 exe 文件

header("Location: $url");

【讨论】:

  • 我无法让它与第一种方法一起使用,但使用“位置”的第二种方法似乎效果很好。谢谢。
  • 现在出现了第二个问题。使用这种新技术,用户似乎仍然可以在 DAP 等下载管理器中看到下载链接。那么真的有办法完全隐藏 URL 吗?
  • 它是软件,我不认为我们可以做到
猜你喜欢
  • 1970-01-01
  • 2012-09-11
  • 1970-01-01
  • 1970-01-01
  • 2012-11-15
  • 1970-01-01
  • 1970-01-01
  • 2018-02-22
  • 1970-01-01
相关资源
最近更新 更多