如何隐藏下载链接 [英] How to hide a download link
本文介绍了如何隐藏下载链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个PHP脚本,允许用户下载文件而不显示URL。当我尝试以下时,我下载的文件是空的。有人可以帮忙吗?
I have a PHP script that is supposed to allow the users to download a file without showing the URL. When I try out the following, the file I download is empty. Could someone please help?
<?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);
?>
推荐答案
你应该这样使用
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: Binary")
header("Content-disposition: attachment; filename=\"file.exe\"");
echo readfile($url);
还根据您的文件应用程序/ zip,应用程序/ pdf等内容类型
also content type based on your file application/zip, application/pdf etc
或更好的一个exe
header("Location: $url");
这篇关于如何隐藏下载链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文