I had a simple little php code that allowed me to force users to download videos from my site rather than playing it in the browser
<?php
$path = $_GET['path'];
header('Content-Disposition: attachment; filename=' . basename($path));
readfile($path);
?>
Since I moved my site to a new server, there seems to be a permission problem where I am getting a 403 Forbidden "You don't have permission to access /downloa开发者_如何学God-stream.php on this server."
the php file is set to the same permissions as before (644). I'm not sure why it's doing this now.
I generally use something like this to force downloads. Remember to change MIME type if you change the type of file being downloaded.
$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.");
}
Try something like this:
<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$path\"\n");
$fp=fopen("$path", "r");
fpassthru($fp);
?>
精彩评论