simbu;11019145 wrote:Once if i click the download link it shows all the resume from resumes folder.But i want to download a particular resume coresponding to candidate id.
Here is my codings.
dow.php:
<?php
mysql_connect("localhost","root","");
mysql_select_db("sample");
if(isset($_GET['id']))
{
$id=intval($_GET['id']);
$query = "SELECT file FROM testing WHERE id=$id";
$result = mysql_query($query) or die('Error, query failed');
list($file, $type) = mysql_fetch_array($result);
header("Content-Disposition: attachment; filename='$file'");
header("Content-length: $size");
header("Content-type: $type");
echo $file;
exit;
}
?>
<html>
<head>
<title>Download a resume</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$query = "SELECT file FROM testing ";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}else{
while(list($file) = mysql_fetch_array($result))
{
?>
<a href="download.php?id=<?php echo $id ?>"><?php echo $file ?></a> <br/>
<?php
}
}
?>
</body>
</html>
download.php:
<?php
if(isset($_GET['id']))
{
// if id is set then get the file with the id from database
mysql_connect("localhost","root","");
mysql_select_db("sample");
$id = $_GET['id'];
$query = "SELECT file FROM testing WHERE id='$id'";
$result = mysql_query($query);
list($file) = mysql_fetch_array($result) or die(mysql_error());
header("Content-length: '$file'");
header("Content-type: application/msword");
header("Content-Disposition: attachment; filename=\'$file\'");
echo "$file";
exit;
}
?>