PHP从USB下载是0字节,权限


PHP download is 0 bytes from USB, permissions?

我在使用php下载文件时遇到问题。它一直在工作,直到我最近将我的web服务器安装在u盘上,以便在上线之前测试一些新的修改。

一切正常,直到我在u盘上测试它,但是在从u盘运行服务器后,我能够下载一个文件,但是它是0字节。

我正在使用一种相当标准的下载技术,这种技术在互联网上都有记录:

//test if a parameter was passed
if (isset($_GET['download'])) {
if (!empty($_GET['download'])) {
$files = $_GET['download'];
download($files);
}
}
//download function
function download($files){
if(!file_exists($files)){
die('Error');
}else{
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename='.basename($path));
header('Content-Type: application/octet-stream');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
ob_start();
flush();
readfile($files);
exit;
}
}

我相信检查文件是否存在行会阻止下载不存在的文件…但是我还是可以下载一个空文件。

此刻,我认为这可能是一个特权问题,但我无法验证,在网上寻找的文件确实存在于usb和硬盘驱动器,所以也许它通过了测试,但不允许从usb读取?

您使用了错误的变量来检查文件大小,因此您总是告诉收件人大小为零。

你应该用filesize($files)代替。