限制来宾用户下载任何文件


restrict guest user to download any file

我有一个下载ppt文件的页面。我想添加一个功能,不提供登录凭据,页面将不会被下载。我的代码是:

if(!isset($_SESSION['user']) && basename($_SERVER['PHP_SELF']) == 'XYZ.ppt'){
    header('location:index.php');
}

但是在浏览器中,如果我输入那个ppt文件的完整路径,那么它就不会检查会话,而是自动下载。

在php中,您可以下载如下

<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>