#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0

    How to download a corresponding resume from folder in wamp server directory?


    Hello,

    I need to download a corresponding resume in localhost ->wamp ->www- >resumes folder.

    Here's my coding.

    <?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.

    If anyone know the solution let me know.
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2002
    Location
    Seattle, U.S.A.
    Posts
    712
    Rep Power
    13
    Show the final html your link creates. It seems like your link isn't right and it's showing you a directory of resumes. Also make sure you encode your $row['file'] so that it's "proper" (said with a british accent) html.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0
    Originally Posted by msteudel
    Show the final html your link creates. It seems like your link isn't right and it's showing you a directory of resumes. Also make sure you encode your $row['file'] so that it's "proper" (said with a british accent) html.
    I tried some other codings.

    Here is my html download link.

    <a href="download1.php?id=<?php echo "$id"; ?>Download a file</a>

    Here is my download1.php code:

    <?php

    $path = $_SERVER['DOCUMENT_ROOT'] . "/resumes/";
    $fullPath = $path.$_GET['download_file'];
    if ($fd = fopen ($fullPath, "r")) {
    $fsize = filesize($fullPath);
    $path_parts = pathinfo($fullPath);
    $ext = strtolower($path_parts["extension"]);
    switch ($ext) {
    case "pdf":
    header("Content-type: application/pdf");
    header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
    default;
    header("Content-type: application/octet-stream");
    header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
    }
    header("Content-length: $fsize");
    header("Cache-control: private");
    while(!feof($fd)) {
    $buffer = fread($fd, 2048);
    echo $buffer;
    }
    }
    fclose ($fd);
    exit;
    ?>
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    Look at your links final output to see its full address. Does it end with an 'id' value, or simply 'download1.php?id=' ?

    If nothing after your equal sign, your 'id' variable is not being set, and this is what you will need to look into.

    If an 'id' shows after the equal sign, does it define correctly? Does your 'id' just hold a number, or a full filename? In this case, it will need to be a full filename to define the file you are downloading. filename.type
    Last edited by Triple_Nothing; November 28th, 2012 at 10:05 AM.

IMN logo majestic logo threadwatch logo seochat tools logo