Im trying to download uploaded file in my database but I cant. Please see the below code.
我试图在我的数据库中下载上传的文件,但我不能。请参阅以下代码。
$filepath = "upload/".$filename;
$ filepath =“upload /".$ filename;
<table class="main_table" border="1">
<tr class="tb_row">
<?php
while($row = mysql_fetch_array($select)){
?>
<td class="tb_dt"><?php echo $row['position']?></td>
<td class="tb_dt"><?php echo $row['trainings']?></td>
<td class="tb_dt"><?php echo $row['tr_date']?></td>
<td><a href="download.php?name=<?php echo $row['img_path'];?>"> download </a></td>
</tr>
<?php } ?>
</table>
1 个解决方案
#1
0
use this
download.php
<?php
$file= $_GET['name'];// make sure it should be a correct path
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
?>
#1
0
use this
download.php
<?php
$file= $_GET['name'];// make sure it should be a correct path
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
?>