在我的求职门户项目中,我将求职者的数据存储在MySQL数据库中。我已将他们上传的简历存储在上传文件夹中。我可以通过分页为雇主检索求职者的数据。我想创建一个每个求职者的下载简历链接,在分页结果中包含他的数据。如何在分页中添加每个搜索结果的上传文件夹中的简历文件的下载简历链接?
如果我理解了这个问题,这很容易。因为你在上传文件夹中有简历文件。只需从数据库中选择文件名并存储在变量中,比如$filename
,就像一样
$filename = $row['cv_filename']; // supposing $row contains the field of database
然后,在定位到该文件的链接中使用文件夹名称前缀。
$prefix = "uploads/resume";
echo "<a href='$prefix/$filename'>Download CV </a>";
在此处查找解决方案:http://www.ssdtutorials.com/tutorials/title/download-file-with-php.html
因为我想下载的文件是动态的,与每个求职者的数据相关。我使用while循环从数据库中检索文件名。
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
{
$filename = $row[0];
echo "<p><a href='download.php?file=$filename'> Download Resume </a></p>";
}
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
阅读完整示例@http://onlamp.com/pub/a/php/2000/09/15/php_mysql.html?page=3