我试图在我的数据库中下载上传的文件,但我不能。请看下面的代码。
$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>

最佳答案

用这个

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;
    }

?>

10-07 12:53
查看更多