I want to download file from my uploads table using the attribute sub_name,
need help. I have this code of two PHP
file one shows the files other downloads it but it's not working.
The uplaods table include sub_name, upload_name, file_content (which is actually the uploaded file) .
My code (the table from which data is sent to be downloaded is):
<?php
include_once("functions.php");
$query="SELECT * from uploads";
$rs = execute_query($query);
?>
<form action="s_downfinl.php" method="post" enctype="multipart/form-data">
<table border="groove" cellpadding="15px">
<tr>
<td>Subject Name</td>
<td>upload name</td>
<td>Download</td>
</tr>
<?php
while ($row = mysql_fetch_assoc($rs)){
echo "<tr><td>";
echo $row['sub_name']."</td><td>";
echo $row['upload_name']."</td>";
echo "<td><a href='s_downfinl.php?nama=".$file."'>download</a></td>";
}
echo "</table>";
?>
</form>
downlaod.php
<?php
include_once"functions.php()";
$query = "SELECT * FROM uploads WHERE sub_name = $sub_name";
$rs = execute_query($query);
$name= $_GET['nama'];
download($name);
function download($name){
$file = $nama_fail;
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
}
?>
fuctions.php (for database connection)
<?php
function execute_query($query){
$connection = mysql_connect("localhost","root","");
mysql_select_db("ascs",$connection);
$result_set = mysql_query($query);
mysql_close($connection);
return $result_set;
}
?>