SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with download script

    Ok guys ive had this working before but its stopped working for some reason, can anyone see any reason why, i get the box up and can download, but the file is coprruted when i try to open:

    PHP Code:
    if ((isset($_POST['submit'])) AND ($_POST['submit'] == "Download")) {

        
    $id $_POST['downloads'];
        
        
    $connect mysql_connect('localhost''##, '##') or die (mysql_error());
        
    mysql_select_db('radiolinks'$connect);
            
        
    $result mysql_query("SELECT * FROM tabDownloads WHERE Id='$id'") or die (mysql_error());
        
    $row mysql_fetch_array($result);
        
        
    $size $row['dowSize'];
        
    $type $row['dowType'];
        
    $name $row['dowName'];
        
    $link "../files/".$row['dowLink'];
        
        
        
    header('Content-Description: File Transfer');
        
    header("Content-Type: application/download");
        
    header("Content-Disposition: attachment; filename=\"".basename($link)."\";");
        
    header('Content-Length: ' filesize($link));
        
        
    readfile($link) OR die(); 
        

    As i said this has worked in the past but my main prority is to get it working now, so if any of it needs changing, just let me know as i cant really see whats wrong with it.

    Thanks in advance

    p.s just to clear up the obvious, yes the values are coming out the database as they are displaying in the download box when it opens, but the file is corrpted when i try to download
    Last edited by webnoob; Nov 20, 2006 at 07:09.
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  2. #2
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This may be a stupid question but have you tried different files?

  3. #3
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well its kind of funny, ive just tested a few files now, a css file downloaded and opened fine using dreamweaver, it then thought the rest of the files were css files aswell. I tried opening a downloaded jpg and that didnt work, the same with a word document, it just opened up a text version of my site
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    It might be an idea to try in different browsers and if the result is the same you might need to be more specific with your Content-Type: application/.... and make it more tuned towards the type of file you are downloading.

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    debug
    PHP Code:
     // instead of
        
    header('Content-Description: File Transfer'); 
        
    header("Content-Type: application/download"); 
        
    header("Content-Disposition: attachment; filename=\"".basename($link)."\";"); 
        
    header('Content-Length: ' filesize($link));
    // do
        
    echo("Content-Disposition: attachment; filename=\"".basename($link)."\";"); 
        echo(
    'Content-Length: ' filesize($link));
    //var_dump() your other variables.
    readfile($link) OR die(); 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •