Every time I use this code and download the file, I get an errors. I assume this is because of the path to the file.
The download.php file is located in /modules/ and is included within index.php on root (inside htdocs/project/) / . The file is located on /modules/download/file.zip
What could be the cause? The URL should be system path? What if I don't want to use system path? Or what is my other issue here?
$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();
Error:
<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 />