簡體   English   中英

我如何下載上傳的文件?

[英]How I can download uploaded file?

我試圖在我的數據庫中下載上傳的文件,但我不能。 請參閱以下代碼。

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

?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM