【发布时间】:2014-11-13 05:56:36
【问题描述】:
每次我使用此代码并下载文件时,都会出现错误。我认为这是因为文件的路径。
download.php 文件位于 /modules/ 并包含在根目录下的 index.php 中(在 htdocs/project/ 内)/ 。该文件位于 /modules/download/file.zip
可能是什么原因? URL应该是系统路径?如果我不想使用系统路径怎么办?或者我的其他问题是什么?
$stmt = $this->GetDatabaseConnection()->prepare('SELECT * FROM download_files WHERE id=?');
$stmt->bind_param('i', $_GET['file']);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id, $name, $desc, $filename, $size, $added, $clicks, $uclicks);
$stmt->fetch();
if($stmt->num_rows > 0) {
$fakeFileName= $name . '.zip';
$realFileName = $filename;
$file = "download/".$realFileName;
$fp = fopen($file, 'rb');
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: Binary");
header("Content-Disposition: attachment; filename=$fakeFileName");
header("Content-Length: " . filesize($file));
fpassthru($fp);
exit;
}
$stmt->free_result();
$stmt->close();
错误:
<b>Warning</b>: fopen(download/6694488-PHPUploadFile.zip): failed to open stream: No such file or directory in <b>C:\xampp\htdocs\project\modules\download.inc.php</b> on line <b>27</b><br />
<br />
<b>Warning</b>: filesize(): stat failed for download/6694488-PHPUploadFile.zip in <b>C:\xampp\htdocs\project\modules\download.inc.php</b> on line <b>31</b><br />
<br />
<b>Warning</b>: fpassthru() expects parameter 1 to be resource, boolean given in <b>C:\xampp\htdocs\project\modules\download.inc.php</b> on line <b>32</b><br />
【问题讨论】:
-
例如 '6694488-PHPUploadFile.zip' 是正确的。并且该文件存在于服务器上的“modules/download/6694488-PHPUploadFile.zip”中。