August 19, 2012

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

Question by Yogesh Rawal

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?

Answer by Yogesh Rawal

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

Answer by Starx

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>";
...

Please fill the form - I will response as fast as I can!