Results 1 to 5 of 5
  1. #1

    Downloading File

    How do you get PHP to start a download of a file (lets say a .zip)?

    Here is my file:

    PHP Code:
    <?php
    include("functions.php");
    if (!
    db_connect())
    {
    echo 
    "Error: Could not connect to database. Please Contact Admin";
    exit;
    }
    $result mysql_query("select * from files WHERE id='$id' AND status='0'");
    $row mysql_fetch_array($result);

    if(
    mysql_num_rows($result)==0)
    {
    echo 
    "Error: Could not find file in database. Please Contact Admin";
    exit;
    }

    $file stripslashes($row['url']);
    $downloads $row['downloads']+1;
    $fp fopen($file"r");

    if(!
    fp)
    {
    echo 
    "Error: Could not download file. Please Contact Admin";
    exit;
    }
    else
    {
    $query "update files set downloads='".$downloads."' where id='".$id."'";
      
    $result mysql_query($query);
    echo 
    "You may close this window.";
    fclose($fp);
    exit;
    }

    ?>
    The program finds the URL (Ex: http://www.atlanticrail.com/files/ac0001.zip) and then I need it to start a download.

    I don't get any errors, just the "You may close this window" message. Meaning it opened the file.
    www.atlanticrail.com

  2. #2
    Join Date
    Dec 2000
    Location
    San Diego, CA
    Posts
    1,571
    You're just in luck:

    http://www.webhostingtalk.com/showth...threadid=70867

    There should be enough info in that thread to help you.
    -Mooneer
    Thoughtbug Software: Hosting shouldn't require any thought.
    Legitimate host? Support the Code of Ethical Conduct

  3. #3
    I saw that... I didn't find much help there. Thanks, though.

    Anyway... in the few minutes, I found another soultion to my problem. So my script works now.

    However, if anyone has any other ideas I would like to hear them.
    www.atlanticrail.com

  4. #4
    Join Date
    Sep 2002
    Posts
    167
    www.hotscripts.com/PHP/Scripts_and_Programs/ File_Manipulation/Download_Systems/

    You can watch at the above link.

  5. #5
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    That linked thread gives you the PHP code to force a file download (rather than opening it in the browser)

Posting Permissions

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