I am trying to create a download link for each users in the database to download a each of their PDF files. I have used the following code
$sqlh = mysql_query("SELECT * FROM tbl_health", $con) or die(mysql_error());
$no = 1;
while($data = mysql_fetch_array($sqlh)){
$no++;
$data['link'];
echo "<a href='view.php?id=" .$data['health_id']. "'>Download</a>";
}
my view.php is
if(isset($_GET['id'])){
$sql = mysql_query("SELECT * FROM tbl_health WHERE health_id='".$_GET['id']."'") or die(mysql_error());
echo $_GET['id'];
$data = mysql_fetch_array($sql);
$file = $data['link'];
$name = "health/".$file;
header("Content-Disposition: attachment; filename=". urlencode($file));
header("Content-Type: application/download");
header("Content-Length: ". filesize($name));
$fp = fopen($name, "r");
//echo fread($fp, 65536);
readfile($fp);
fclose($fp); }
the pdf can be downloaded but when open to view its empty. Please help