Yogesh Rawal
Yogesh Rawal

Reputation: 105

How to create a download link for a file using PHP?

In my job portal project, I have stored the job seekers data in MySQL Database. I have stored their uploaded resumes in the upload folder. I am able to retrieve that data of job seekers for the employers through pagination. And I want to create a download resume link of each job seeker with his data in the pagination result. How I can add the download resume link for the resume files from upload folder with each search result in the pagination?

Upvotes: 0

Views: 14988

Answers (3)

Yogesh Rawal
Yogesh Rawal

Reputation: 105

Find the solution here: http://www.ssdtutorials.com/tutorials/title/download-file-with-php.html

As the file which I want to download is dynamic associated with each job seeker's data. I used while loop for retrieving the file name from database.

    $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>";
    }

Upvotes: 1

Starx
Starx

Reputation: 79069

If I understood the question, this is very easy. Since you have the resume files in the upload folder. Just select the file name from the database and store on a variable lets say $filename, Like

$filename = $row['cv_filename']; // supposing $row contains the field of database

Then, use prefix the folder name in the anchor a link to that file.

$prefix = "uploads/resume";
echo "<a href='$prefix/$filename'>Download CV </a>";

Upvotes: 2

Kolyunya
Kolyunya

Reputation: 6240

header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;

read full example @ http://onlamp.com/pub/a/php/2000/09/15/php_mysql.html?page=3

Upvotes: 0

Related Questions