SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict sedna's Avatar
    Join Date
    Jan 2006
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    download file problem

    hey all,

    i am having some problems trying to download a file here is my hacks.php page

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <table width="50&#37;" border="0" cellspacing="0" cellpadding="3" align="left" >
    <tr>
    <th align="left">Hack Name</th>
    <th align="left">Description</th>
    <th align="left">Version</th>
    <th align="left">Author</th>
    <th align="left">Download</th>
    </tr>

    <?php
    include("config.php");

    // connect to the mysql server
    $link = mysql_connect($server, $db_user, $db_pass)
    or die ("Could not connect to mysql because ".mysql_error());

    // select the database
    mysql_select_db($database)
    or die ("Could not select database because ".mysql_error());
    echo "<h1> $hackname </h1>";
    $search2=mysql_query("SELECT userid FROM users");
    $search=mysql_query("SELECT * FROM hacks WHERE `hacksid`={$_GET['hacksid']}");
    while($result=mysql_fetch_array($search)){
    echo '<h1>';
    echo $hackname = $result['hackname'] ;
    echo '</h1>';
    echo "<tr valign='top'>\n";
    $hacksid = $result['hacksid'];
    $hackname = $result['hackname'];
    $description = $result['description'];
    $version = $result['version'];
    $username = $result['username'];


    echo "<td>$hackname</td>\n";
    echo "<td>$description</td>\n";
    echo "<td>$version</td>\n";
    echo "<td><a href='profile.php?userid=$username'>$username</a></td>\n";
    echo "<td><a href='dload.php?hacksid=$hacksid'>Download</a></td>\n";
    echo "</tr>\n";
    }

    ?>
    </body>
    </html>
    </table>

    and here is my dload.php page

    <?php header("Content-Disposition: attachment; filename=$hackname");
    header("Content-length: $filedata");
    header("Content-type: $mimetype");
    echo $filedata;?>


    <?php
    include("config.php");

    // connect to the mysql server
    $link = mysql_connect($server, $db_user, $db_pass)
    or die ("Could not connect to mysql because ".mysql_error());

    // select the database
    mysql_select_db($database)
    or die ("Could not select database because ".mysql_error());

    if(isset($_GET['hacksid']))
    {
    $id = $_GET['hacksid'];
    $query = "SELECT hackname, mimetype, filedata FROM hacks WHERE hacksid = '$hacksid'";
    $result = mysql_query($query) or die('Error, query failed'.mysql_error());
    list($hackname, $mimetype, $filedata) = mysql_fetch_array($result);




    exit;
    }

    ?>



    for some strange resson it downloads the dload.php and not the hackfile wich is a zip?

    any help i would be appricated

  2. #2
    SitePoint Addict say's Avatar
    Join Date
    Sep 2003
    Location
    At work
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What the... is this a 2 file or a 1 file?

    PHP Code:
    <?php header("Content-Disposition: attachment; filename=$hackname");
    header("Content-length: $filedata");
    header("Content-type: $mimetype");
    echo 
    $filedata;?>


    <?php
    include("config.php");

    // connect to the mysql server
    $link mysql_connect($server$db_user$db_pass)
    or die (
    "Could not connect to mysql because ".mysql_error());

    // select the database
    mysql_select_db($database)
    or die (
    "Could not select database because ".mysql_error());

    if(isset(
    $_GET['hacksid']))
    {
    $id $_GET['hacksid'];
    $query "SELECT hackname, mimetype, filedata FROM hacks WHERE hacksid = '$hacksid'";
    $result mysql_query($query) or die('Error, query failed'.mysql_error());
    list(
    $hackname$mimetype$filedata) = mysql_fetch_array($result);




    exit;
    }

    ?>
    If 1 file, then it makes sense that it should look like this?

    PHP Code:
    <?php
    include("config.php");

    // connect to the mysql server
    $link mysql_connect($server$db_user$db_pass)
    or die (
    "Could not connect to mysql because ".mysql_error());

    // select the database
    mysql_select_db($database)
    or die (
    "Could not select database because ".mysql_error());

    if(isset(
    $_GET['hacksid']))
    {
    $id $_GET['hacksid'];
    $query "SELECT hackname, mimetype, filedata FROM hacks WHERE hacksid = '$hacksid'";
    $result mysql_query($query) or die('Error, query failed'.mysql_error());
    list(
    $hackname$mimetype$filedata) = mysql_fetch_array($result);

    header("Content-Disposition: attachment; filename=$hackname");
    header("Content-length: $filedata");
    header("Content-type: $mimetype");
    echo 
    $filedata;
    exit;
    }

    ?>
    BTW, to post code, please use the [PHP] tag so as everyone can read better in order to help.


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
  •