files wont open

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mubs
    New Member
    • Mar 2007
    • 77

    files wont open

    I have a download script which holds files which have been uploaded by the users.. the files are shown on this page but once i try to open them, nothin happens...any1 help

    script

    [PHP]<?php require_once('C onnections/mysql_connect.p hp'); ?>
    <?php
    if(isset($_GET['name']))
    {

    $name = $_GET['name'];
    $query = "SELECT type, size, content FROM uploadfiles WHERE name = '$name'";
    $result = mysql_query($qu ery) or die('Error, query failed');
    list($name, $type, $size, $content) = mysql_fetch_arr ay($result);

    header("Content-Disposition: attachment; filename=$name" );
    header("Content-length: $size");
    header("Content-type: $type");
    echo $content;

    exit;
    }
    mysql_select_db ($database_mysq l_connect, $mysql_connect) ;
    $query_Recordse t1 = "SELECT * FROM uploadfiles";
    $Recordset1 = mysql_query($qu ery_Recordset1, $mysql_connect) or die(mysql_error ());
    $row_Recordset1 = mysql_fetch_ass oc($Recordset1) ;
    $totalRows_Reco rdset1 = mysql_num_rows( $Recordset1);

    mysql_free_resu lt($Recordset1) ;

    ?>
    <html>
    <head>
    <title>Downlo ad File From MySQL</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?

    $query = "SELECT name FROM uploadfiles";
    $result = mysql_query($qu ery) or die('Error, query failed');
    if(mysql_num_ro ws($result) == 0)
    {
    echo "Database is empty
    ";
    }
    else
    {
    while(list($nam e) = mysql_fetch_arr ay($result))
    {
    ?>
    <a href="download. php?id=<?=$id;? >"><?=$name;? >[/url]

    <?
    }
    }

    ?>
    </body>
    </html>[/PHP]
  • tonymanuel
    New Member
    • Jul 2008
    • 4

    #2
    [PHP]
    if(isset($_GET['name']))
    {

    $name = $_GET['name'];
    $query = "SELECT type, size, content FROM uploadfiles WHERE name = '$name'";
    $result = mysql_query($qu ery) or die('Error, query failed');
    list($name, $type, $size, $content) = mysql_fetch_arr ay($result);

    header("Content-Disposition: attachment; filename=$name" );
    header("Content-length: $size");
    header("Content-type: $type");
    echo $content;

    exit;
    }
    [/PHP]

    In your query, you're selecting the type, size and content. However in the list function, you're adding the name variable. So, the name var will store the type, the type will store the size, the size var will store the content and the content will be empty (I think). You don't need to redeclare the name, you got it in the URL. Try

    [PHP]
    list($type, $size, $content) = mysql_fetch_arr ay($result);
    [/PHP]

    instead of

    [PHP]
    list($name, $type, $size, $content) = mysql_fetch_arr ay($result);
    [/PHP]

    I hope that this helps you

    Comment

    • Mubs
      New Member
      • Mar 2007
      • 77

      #3
      Originally posted by tonymanuel
      [PHP]
      if(isset($_GET['name']))
      {

      $name = $_GET['name'];
      $query = "SELECT type, size, content FROM uploadfiles WHERE name = '$name'";
      $result = mysql_query($qu ery) or die('Error, query failed');
      list($name, $type, $size, $content) = mysql_fetch_arr ay($result);

      header("Content-Disposition: attachment; filename=$name" );
      header("Content-length: $size");
      header("Content-type: $type");
      echo $content;

      exit;
      }
      [/PHP]

      In your query, you're selecting the type, size and content. However in the list function, you're adding the name variable. So, the name var will store the type, the type will store the size, the size var will store the content and the content will be empty (I think). You don't need to redeclare the name, you got it in the URL. Try

      [PHP]
      list($type, $size, $content) = mysql_fetch_arr ay($result);
      [/PHP]

      instead of

      [PHP]
      list($name, $type, $size, $content) = mysql_fetch_arr ay($result);
      [/PHP]

      I hope that this helps you

      i have got it to open the files thanx...but 1 problem, the files are all shown in a single line instead of a column...

      Comment

      • tonymanuel
        New Member
        • Jul 2008
        • 4

        #4
        Originally posted by Mubs
        i have got it to open the files thanx...but 1 problem, the files are all shown in a single line instead of a column...
        add a breakline '<br />' after each link.

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by tonymanuel
          [PHP]
          if(isset($_GET['name']))
          {

          $name = $_GET['name'];
          $query = "SELECT type, size, content FROM uploadfiles WHERE name = '$name'";
          $result = mysql_query($qu ery) or die('Error, query failed');
          list($name, $type, $size, $content) = mysql_fetch_arr ay($result);

          header("Content-Disposition: attachment; filename=$name" );
          header("Content-length: $size");
          header("Content-type: $type");
          echo $content;

          exit;
          }
          [/PHP]

          In your query, you're selecting the type, size and content. However in the list function, you're adding the name variable. So, the name var will store the type, the type will store the size, the size var will store the content and the content will be empty (I think). You don't need to redeclare the name, you got it in the URL. Try

          [PHP]
          list($type, $size, $content) = mysql_fetch_arr ay($result);
          [/PHP]

          instead of

          [PHP]
          list($name, $type, $size, $content) = mysql_fetch_arr ay($result);
          [/PHP]

          I hope that this helps you
          Applause needed - that was a great catch.

          OP: In your or die() statements, you should put something useful there. i.e. mysql_error() this holds the error the query generated.

          Comment

          Working...