Hello,

I need to download a single resume corresponding to id and here is my codings.

<?php

mysql_connect("localhost","root","");
mysql_select_db("sample");

?>

<?php
if(isset($GET['id']))
{
$id = $
GET['id'];
$query = mysql_query("SELECT file FROM testing WHERE id='$id' ");
$row = mysql_fetch_array($query);
}
?>
<a href='resumes/'<?= $row['file'] ?>Download</a>

it works,but it shows all the resumes in the resumes folder.but i need to download only the corresponding resume.

If anyone knows, let me know.

    What does "shows all resumes in the resumes folder" mean? For example, does the link take you to a standard directory index/listing that shows a list of files? Also, what does the resulting HTML markup look like when that code is executed?

      bradgrafelman;11019051 wrote:

      What does "shows all resumes in the resumes folder" mean? For example, does the link take you to a standard directory index/listing that shows a list of files? Also, what does the resulting HTML markup look like when that code is executed?

      Once i click the download link it goes to resumes folder and displays all the resumes.But if click the download link it should be download the corresponding resume from resumes folder.

        ...and what is the problem you're having?

          Weedpacket;11019139 wrote:

          ...and what is the problem you're having?

          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.

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

            ?>

              You haven't told us but I'm going to guess that your code doesn't do what you want (if it did you wouldn't be posting).

              So what is it doing?

              I do see one thing that's obviously wrong. You're not using the forum's markup tags for PHP code. Oh, and

              header("Content-length: '$file'");
              header("Content-type: application/msword");
              header("Content-Disposition: attachment; filename=\'$file\'");
              echo "$file";
              

              According to that, the file name, the file size, and the file contents are all exactly the same thing. Which would work if you have a file named "1" that contains "1" and is therefore 1 byte long, but that's not a very interesting file.

                Write a Reply...