-3

Presently I am working on a company's website on which if job seeker posts their CV, it will be visible in the admin panel with a download option.

Now I need help in that download part. In admin section i am displaying information about the newly registered job seeker, along with a button which should allow administrator to download the job seeker's CV. I need at least one working example for doing this at least, if I got a good discussion about file downloading I will be very greatful.

I worked on website having file download option in asp.net in C# but no idea how to achieve it in html PHP.

4

2 回答 2

1

见你说你已经有一个下载链接。只需链接到文件。

<a href="download.php?file=user-cv.pdf">Download</a>

在 中download.php,给出Content-disposition: attachment;这样的方式:

<?php
    # Sanitize the code to avoid injection
    $file = "uploads/" . stripslashes(str_replace(array("..", "/"), "", $_GET["file"]));
    header('Content-Disposition: attachment; filename="' . $file . '"');
    header('Content-type: application/pdf');
    readfile($file);
    die();
?>

警告:

正如Corbin所说,如果人们试图直接访问该文件,就会存在一个巨大的安全漏洞。最好将它作为文件名,文件类型存储在数据库中,以便可以这样访问:

<a href="download.php?user=praveenscience">Download</a>

在 PHP 代码中,从 MySQL 服务器获取结果并以这种方式下载:

<?php
    $file = mysql_result(/* Query Here */);
    header('Content-Disposition: attachment; filename="' . $file["filename"] . '"');
    header('Content-type: ' . $file["mimetype"]);
    readfile($file["filename"]);
    die();
?>
于 2012-11-08T06:08:20.727 回答
0

提供简历的完整路径以及服务器中的文件名作为下载按钮的超链接

像这样:

<a href="<?php echo 'path of file/filename';?>"><img src="download.png"></a>
于 2012-11-08T06:10:05.357 回答