在HTML中隐藏下载链接


好的,你不能用普通的HTML做到这一点。您可以使用所有类型的技巧,但它们可能是用户体验的问题,您将使用服务器端语言。

你能做的就是创建一个php页面,以你想要的方式命名它(比方说download.php),然后链接到那个页面。页面应该是这样的:

代码语言:javascript运行复制// Path to the file

$path = '/home/folder/yourfile.pdf';

// This is based on file type of $path, but not always needed

$mm_type = "application/octet-stream";

//Set headers

header("Pragma: public");

header("Expires: 0");

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header("Cache-Control: public");

header("Content-Description: File Transfer");

header("Content-Type: " . $mm_type);

header("Content-Length: " .(string)(filesize($path)) );

header('Content-Disposition: attachment; filename="'.basename($path).'"');

header("Content-Transfer-Encoding: binary\n");

// Outputs the content of the file

readfile($path);

exit();这样,您只需链接到您的download.php页面,它就会下载/打开PDF,如下所示:

代码语言:javascript运行复制Download基于 BenjaminC 建议编辑的建议

另一个机会是将其连接到数据库。数据库有一个名为downloads_table的表,里面有两个字段:

char(32)

downloaded:int(1) dafault 0

秘诀

然后创建一个md5字符串$secret =md5(rand1000,9999999);

将其放在secret字段中,创建链接:

代码语言:javascript运行复制 Download用户收到/看到一个链接,当按下时,你要编辑上面代码的第一行,如果downloaded字段=0,则签入数据库,然后继续下载,否则该用户会看到一个错误页面。这是因为它只能下载一次。

愴的意思,愴的解释,愴的拼音,愴的部首,愴的笔顺
优酷弹幕怎么关闭 电脑网页优酷弹幕关闭教程