PHP脚本强制下载不起作用

|| 我有一个简单的小php代码,可让我强迫用户从我的网站下载视频,而不是在浏览器中播放视频
<?php

$path = $_GET[\'path\'];
header(\'Content-Disposition: attachment; filename=\' . basename($path));
readfile($path);

?>
自从我将网站移到新服务器上以来,似乎出现了权限问题,我收到了403禁止访问权限“您无权访问此服务器上的/download-stream.php。” php文件设置为与以前相同的权限(644)。我不确定为什么现在要这样做。     
已邀请:
        我通常使用类似的方法来强制下载。如果您更改要下载的文件的类型,请记住要更改MIME类型。
        $attachment_location = $_SERVER[\"DOCUMENT_ROOT\"] . \"/file.zip\";
        if (file_exists($attachment_location)) {

            header($_SERVER[\"SERVER_PROTOCOL\"] . \" 200 OK\");
            header(\"Cache-Control: public\"); // needed for i.e.
            header(\"Content-Type: application/zip\");
            header(\"Content-Transfer-Encoding: Binary\");
            header(\"Content-Length:\".filesize($attachment_location));
            header(\"Content-Disposition: attachment; filename=file.zip\");
            readfile($attachment_location);
            die();        
        } else {
            die(\"Error: File not found.\");
        } 
    
        尝试这样的事情:
<?php
header(\"Content-type: application/octet-stream\");
header(\"Content-Disposition: attachment; filename=\\\"$path\\\"\\n\");
$fp=fopen(\"$path\", \"r\");
fpassthru($fp);
?>     

要回复问题请先登录注册