4

Im trying to download uploaded file in my database but I cant. Please see the below code.

$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>
Abbas
  • 412
  • 2
  • 9
Key K
  • 169
  • 13

1 Answers1

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

?>
Passionate Coder
  • 7,154
  • 2
  • 19
  • 44