www.webdeveloper.com
Results 1 to 2 of 2

Thread: PHP file download script

  1. #1
    Join Date
    Jul 2007
    Posts
    5

    PHP file download script

    Hi,

    I want create a download dialog on my web page to download files on a server. Could someone provide me with simple PHP script to put on my web page to do this? i.e something that goes into

    <a href="php script">Download</a>

    Any help appreciated,

    Ruth

  2. #2
    Join Date
    May 2007
    Location
    Cleveland, OH
    Posts
    1,403
    Here's the script I use to download files from a database:
    PHP Code:
    <?php
    session_start
    ();
    $userAccess $_SESSION['level'];

    if(isset(
    $_GET['id']))
    {
    //download file

    include ('dbconnect.php');

    $id $_GET['id'];

    $query "SELECT name, type, size, content FROM upload WHERE id='$id' AND access<='$userAccess'";

    $result mysql_query($query) or die(mysql_error());

    list(
    $name$type$size$content) = mysql_fetch_array($result);

    header('Cache-Control: maxage=3600'); 
    header('Pragma: public');
    header("Content-length: $size");
    header("Content-type: $type");
    header('Content-Disposition: attachment; filename="'.$name.'"');
    echo 
    $content;

    mysql_close($db);
    exit;
    }

    ?>
    And the link to download the file looks like this:
    HTML Code:
    <a href="download.php?id=37">Download</a>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles