I have files uploaded on server folder and its path is saved in database. sample view of table is:
id name resume
1 N1 resume/abc.doc
2 N2 resume/def.pdf
On a click of a button i wish to download the files (format of file would mostly be docx, pdf) from the server to the system. The code that i have written downloads a file but it is either empty or corrupted. Can anyone please tell how to download files from server
<a href="download.php?candidateid=<? echo $candidateid ?>">Download</a>
download.php
$candidateid=$_GET['candidateid'];
$filename = "Filename.docx";
header("Content-Disposition: attachment; filename=\"$filename\"");
$flag = false;
$sql = "SELECT resume FROM candidates where id='".$candidateid."' ";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
if (!$flag)
{
// display field/column names as first row
echo implode("\t", array_keys($row)) . "\r\n";
$flag = true;
}
echo implode("\t", array_values($row)) . "\r\n";
}
}