file upload to database help

  • virose
  • Novice
  • Novice
  • virose
  • Posts: 27
  • Loc: florida

Post 3+ Months Ago

Hello Guys,

Any help with this would be greatly appreciated

It appears to be connecting fine. my problem is i cant get the upload code to insert a file into the database.
I cant locate the issue with the code i have ran it on a test server as well as on my main servers.

I have double tipple checked the DB names and TABLE name the one on this are dummy the problem i think is in the logic somewhere.

This is the connect to database code

Code: [ Select ]
<?php
    $db = mysql_connect("localhost", "binary_user", "binary_password");
    mysql_select_db("binary_files", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
?>
  1. <?php
  2.     $db = mysql_connect("localhost", "binary_user", "binary_password");
  3.     mysql_select_db("binary_files", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
  4. ?>


this is the upload code

Code: [ Select ]
<?php
if ($action == "upload") {
// ok, let's get the uploaded data and insert it into the db now
include "open_db.inc";

if (isset($binFile) && $binFile != "none") {
    $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
    $strDescription = addslashes(nl2br($txtDescription));
    $sql = "INSERT INTO tbl_Files ";
    $sql .= "(description, bin_data, filename, filesize, filetype) ";
    $sql .= "VALUES ('$strDescription', '$data', ";
    $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
    $result = mysql_query($sql, $db);
    mysql_free_result($result); // it's always nice to clean up!
    echo "Thank you. The new file was successfully added to our database.<br><br>";
    echo "<a href='main.php'>Continue</a>";
}
mysql_close();

} else {
?>
<HTML>
<BODY>
<FORM METHOD="post" ACTION="add.php" ENCTYPE="multipart/form-data">
<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="1000000">
<INPUT TYPE="hidden" NAME="action" VALUE="upload">
<TABLE BORDER="1">
<TR>
<TD>Description: </TD>
<TD><TEXTAREA NAME="txtDescription" ROWS="10" COLS="50"></TEXTAREA></TD>
</TR>
<TR>
<TD>File: </TD>
<TD><INPUT TYPE="file" NAME="binFile"></TD>
</TR>
<TR>
<TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Upload"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
<?php
}
?>
  1. <?php
  2. if ($action == "upload") {
  3. // ok, let's get the uploaded data and insert it into the db now
  4. include "open_db.inc";
  5. if (isset($binFile) && $binFile != "none") {
  6.     $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
  7.     $strDescription = addslashes(nl2br($txtDescription));
  8.     $sql = "INSERT INTO tbl_Files ";
  9.     $sql .= "(description, bin_data, filename, filesize, filetype) ";
  10.     $sql .= "VALUES ('$strDescription', '$data', ";
  11.     $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
  12.     $result = mysql_query($sql, $db);
  13.     mysql_free_result($result); // it's always nice to clean up!
  14.     echo "Thank you. The new file was successfully added to our database.<br><br>";
  15.     echo "<a href='main.php'>Continue</a>";
  16. }
  17. mysql_close();
  18. } else {
  19. ?>
  20. <HTML>
  21. <BODY>
  22. <FORM METHOD="post" ACTION="add.php" ENCTYPE="multipart/form-data">
  23. <INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="1000000">
  24. <INPUT TYPE="hidden" NAME="action" VALUE="upload">
  25. <TABLE BORDER="1">
  26. <TR>
  27. <TD>Description: </TD>
  28. <TD><TEXTAREA NAME="txtDescription" ROWS="10" COLS="50"></TEXTAREA></TD>
  29. </TR>
  30. <TR>
  31. <TD>File: </TD>
  32. <TD><INPUT TYPE="file" NAME="binFile"></TD>
  33. </TR>
  34. <TR>
  35. <TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Upload"></TD>
  36. </TR>
  37. </TABLE>
  38. </FORM>
  39. </BODY>
  40. </HTML>
  41. <?php
  42. }
  43. ?>


Thanks, Again
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Try the following and see what you will get:
PHP Code: [ Select ]
<?php
if ($action == "upload")
{
   // ok, let's get the uploaded data and insert it into the db now
   include "open_db.inc";
 
   if (isset($binFile) && $binFile != "none")
   {
      $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
      $strDescription = addslashes(nl2br($txtDescription));
      $sql = "INSERT INTO tbl_Files ";
      $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
      $sql .= "VALUES ('$strDescription', '$data', ";
      $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
      if($result = mysql_query($sql, $db))
      {
         echo "Thank you. The new file was successfully added to our database.<br><br>";
      }
      else
      {
         echo "There was a problem with adding the file to our database.<br /><br />";
         die(mysql_error());
      }
      mysql_free_result($result); // it's always nice to clean up!
      echo "<a href='main.php'>Continue</a>";
   }
   mysql_close();
}
?>
  1. <?php
  2. if ($action == "upload")
  3. {
  4.    // ok, let's get the uploaded data and insert it into the db now
  5.    include "open_db.inc";
  6.  
  7.    if (isset($binFile) && $binFile != "none")
  8.    {
  9.       $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
  10.       $strDescription = addslashes(nl2br($txtDescription));
  11.       $sql = "INSERT INTO tbl_Files ";
  12.       $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
  13.       $sql .= "VALUES ('$strDescription', '$data', ";
  14.       $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
  15.       if($result = mysql_query($sql, $db))
  16.       {
  17.          echo "Thank you. The new file was successfully added to our database.<br><br>";
  18.       }
  19.       else
  20.       {
  21.          echo "There was a problem with adding the file to our database.<br /><br />";
  22.          die(mysql_error());
  23.       }
  24.       mysql_free_result($result); // it's always nice to clean up!
  25.       echo "<a href='main.php'>Continue</a>";
  26.    }
  27.    mysql_close();
  28. }
  29. ?>
  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

do you have the globals on?

if not then you should have problem, to work around that, you must change

$binFile_name, $binFile_size, $binFile_type

try this

Code: [ Select ]
    <?php
    if ($action == "upload")
    {
        // ok, let's get the uploaded data and insert it into the db now
        include "open_db.inc";
    
        if (isset($binFile) && $binFile != "none")
        {
            $binFile_name = $_FILES['binFile_name']['name'];
            $binFile_size = $_FILES['binFile_name']['size'];
            $binFile_type = $_FILES['binFile_name']['type'];
            $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
         $strDescription = addslashes(nl2br($txtDescription));
         $sql = "INSERT INTO tbl_Files ";
         $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
         $sql .= "VALUES ('$strDescription', '$data', ";
         $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
         if($result = mysql_query($sql, $db))
         {
             echo "Thank you. The new file was successfully added to our database.<br><br>";
         }
         else
         {
             echo "There was a problem with adding the file to our database.<br /><br />";
             die(mysql_error());
         }
         mysql_free_result($result); // it's always nice to clean up!
         echo "<a href='main.php'>Continue</a>";
     }
     mysql_close();
}
?>
  1.     <?php
  2.     if ($action == "upload")
  3.     {
  4.         // ok, let's get the uploaded data and insert it into the db now
  5.         include "open_db.inc";
  6.     
  7.         if (isset($binFile) && $binFile != "none")
  8.         {
  9.             $binFile_name = $_FILES['binFile_name']['name'];
  10.             $binFile_size = $_FILES['binFile_name']['size'];
  11.             $binFile_type = $_FILES['binFile_name']['type'];
  12.             $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
  13.          $strDescription = addslashes(nl2br($txtDescription));
  14.          $sql = "INSERT INTO tbl_Files ";
  15.          $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
  16.          $sql .= "VALUES ('$strDescription', '$data', ";
  17.          $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
  18.          if($result = mysql_query($sql, $db))
  19.          {
  20.              echo "Thank you. The new file was successfully added to our database.<br><br>";
  21.          }
  22.          else
  23.          {
  24.              echo "There was a problem with adding the file to our database.<br /><br />";
  25.              die(mysql_error());
  26.          }
  27.          mysql_free_result($result); // it's always nice to clean up!
  28.          echo "<a href='main.php'>Continue</a>";
  29.      }
  30.      mysql_close();
  31. }
  32. ?>


maybe you have globals on and having problem with SQL.

Firstly, it is not cleared that if you are inserting the whole file into the database or inserting the file name into the database?
The above code is for file name to be inserted. If you want to insert the whole file, then the above code will be different!!
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Code: [ Select ]
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription)
);
$sql = "INSERT INTO tbl_Files ";
$sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
  1. $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
  2. $strDescription = addslashes(nl2br($txtDescription));
  3. $sql = "INSERT INTO tbl_Files ";
  4. $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
  5. $sql .= "VALUES ('$strDescription', '$data', ";
  6. $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";

I'm sure he is putting the contents of the file into it.
  • virose
  • Novice
  • Novice
  • virose
  • Posts: 27
  • Loc: florida

Post 3+ Months Ago

Bogey wrote:
Try the following and see what you will get:
PHP Code: [ Select ]
<?php
if ($action == "upload")
{
    // ok, let's get the uploaded data and insert it into the db now
    include "open_db.inc";
 
    if (isset($binFile) && $binFile != "none")
    {
        $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
        $strDescription = addslashes(nl2br($txtDescription));
        $sql = "INSERT INTO tbl_Files ";
        $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
        $sql .= "VALUES ('$strDescription', '$data', ";
        $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
        if($result = mysql_query($sql, $db))
        {
            echo "Thank you. The new file was successfully added to our database.<br><br>";
        }
        else
        {
            echo "There was a problem with adding the file to our database.<br /><br />";
            die(mysql_error());
        }
        mysql_free_result($result); // it's always nice to clean up!
        echo "<a href='main.php'>Continue</a>";
    }
    mysql_close();
}
?>
  1. <?php
  2. if ($action == "upload")
  3. {
  4.     // ok, let's get the uploaded data and insert it into the db now
  5.     include "open_db.inc";
  6.  
  7.     if (isset($binFile) && $binFile != "none")
  8.     {
  9.         $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
  10.         $strDescription = addslashes(nl2br($txtDescription));
  11.         $sql = "INSERT INTO tbl_Files ";
  12.         $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
  13.         $sql .= "VALUES ('$strDescription', '$data', ";
  14.         $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
  15.         if($result = mysql_query($sql, $db))
  16.         {
  17.             echo "Thank you. The new file was successfully added to our database.<br><br>";
  18.         }
  19.         else
  20.         {
  21.             echo "There was a problem with adding the file to our database.<br /><br />";
  22.             die(mysql_error());
  23.         }
  24.         mysql_free_result($result); // it's always nice to clean up!
  25.         echo "<a href='main.php'>Continue</a>";
  26.     }
  27.     mysql_close();
  28. }
  29. ?>


this is the errors i get with this code block, Thanks for the help. Any more help greatly appreciated. Because i don't understand what is wrong with this code.


ERORRS


$db = mysql_connect("localhost", "jason", "jason"); mysql_select_db("my_family", $db) or die(mysql_errno() . ": " . mysql_error() . "
");
Notice: Undefined variable: db in H:\wamp\www\php_testing\add.php on line 15

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in H:\wamp\www\php_testing\add.php on line 15

There was a problem with adding the file to our database.

END ERRORS
  • virose
  • Novice
  • Novice
  • virose
  • Posts: 27
  • Loc: florida

Post 3+ Months Ago

dark_lord wrote:
do you have the globals on?

if not then you should have problem, to work around that, you must change

$binFile_name, $binFile_size, $binFile_type

try this

Code: [ Select ]
 
    <?php
    if ($action == "upload")
    {
        // ok, let's get the uploaded data and insert it into the db now
        include "open_db.inc";
     
        if (isset($binFile) && $binFile != "none")
        {
            $binFile_name = $_FILES['binFile_name']['name'];
            $binFile_size = $_FILES['binFile_name']['size'];
            $binFile_type = $_FILES['binFile_name']['type'];
            $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
           $strDescription = addslashes(nl2br($txtDescription));
           $sql = "INSERT INTO tbl_Files ";
           $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
           $sql .= "VALUES ('$strDescription', '$data', ";
           $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
           if($result = mysql_query($sql, $db))
           {
               echo "Thank you. The new file was successfully added to our database.<br><br>";
           }
           else
           {
               echo "There was a problem with adding the file to our database.<br /><br />";
               die(mysql_error());
           }
           mysql_free_result($result); // it's always nice to clean up!
           echo "<a href='main.php'>Continue</a>";
       }
       mysql_close();
   }
   ?>
 
  1.  
  2.     <?php
  3.     if ($action == "upload")
  4.     {
  5.         // ok, let's get the uploaded data and insert it into the db now
  6.         include "open_db.inc";
  7.      
  8.         if (isset($binFile) && $binFile != "none")
  9.         {
  10.             $binFile_name = $_FILES['binFile_name']['name'];
  11.             $binFile_size = $_FILES['binFile_name']['size'];
  12.             $binFile_type = $_FILES['binFile_name']['type'];
  13.             $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
  14.            $strDescription = addslashes(nl2br($txtDescription));
  15.            $sql = "INSERT INTO tbl_Files ";
  16.            $sql .= "(`description`, `bin_data`, `filename`, `filesize`, `filetype`) ";
  17.            $sql .= "VALUES ('$strDescription', '$data', ";
  18.            $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
  19.            if($result = mysql_query($sql, $db))
  20.            {
  21.                echo "Thank you. The new file was successfully added to our database.<br><br>";
  22.            }
  23.            else
  24.            {
  25.                echo "There was a problem with adding the file to our database.<br /><br />";
  26.                die(mysql_error());
  27.            }
  28.            mysql_free_result($result); // it's always nice to clean up!
  29.            echo "<a href='main.php'>Continue</a>";
  30.        }
  31.        mysql_close();
  32.    }
  33.    ?>
  34.  


maybe you have globals on and having problem with SQL.

Firstly, it is not cleared that if you are inserting the whole file into the database or inserting the file name into the database?
The above code is for file name to be inserted. If you want to insert the whole file, then the above code will be different!!


This code block produced these erorrs. thanks for the help.
and yes to clarify I am inserting the whole file into a database using the mediumblob setting.


ERRORS


$db = mysql_connect("localhost", "jason", "jason"); mysql_select_db("my_family", $db) or die(mysql_errno() . ": " . mysql_error() . "
");
Notice: Undefined index: binFile_name in H:\wamp\www\php_testing\add.php on line 9

Notice: Undefined index: binFile_name in H:\wamp\www\php_testing\add.php on line 10

Notice: Undefined index: binFile_name in H:\wamp\www\php_testing\add.php on line 11

Notice: Undefined variable: db in H:\wamp\www\php_testing\add.php on line 18

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in H:\wamp\www\php_testing\add.php on line 18
There was a problem with adding the file to our database.

END ERRORS
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

I guess you got the user or password wrong... Have you tried 'root' for the user? Or have you specifically created user 'Jason'?

Also, hide the password if you're not already :lol:
  • virose
  • Novice
  • Novice
  • virose
  • Posts: 27
  • Loc: florida

Post 3+ Months Ago

Hey Bogey,

Thanks for the help on that one, I got it working now. Global's was off for one thing which was causing problems.
And then i had a small issue with my connect code.

I'm not worried about passwords it just a test server on a test pc.


Now the download file is not working.

Think you can help out?

Here is the code if so.

Code: [ Select ]
<?php
if ($id_files) {
include "open_db.inc";

$sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
    
$result = @mysql_query($sql, $db);
$data = @mysql_result($result, 0, "bin_data");
$name = @mysql_result($result, 0, "filename");
$size = @mysql_result($result, 0, "filesize");
$type = @mysql_result($result, 0, "filetype");
    
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
} else { echo 'ERORR IN CODE';}
?>
  1. <?php
  2. if ($id_files) {
  3. include "open_db.inc";
  4. $sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
  5.     
  6. $result = @mysql_query($sql, $db);
  7. $data = @mysql_result($result, 0, "bin_data");
  8. $name = @mysql_result($result, 0, "filename");
  9. $size = @mysql_result($result, 0, "filesize");
  10. $type = @mysql_result($result, 0, "filetype");
  11.     
  12. header("Content-type: $type");
  13. header("Content-length: $size");
  14. header("Content-Disposition: attachment; filename=$name");
  15. header("Content-Description: PHP Generated Data");
  16. echo $data;
  17. } else { echo 'ERORR IN CODE';}
  18. ?>


Here are the errors i get.

ERRORS


Notice: Undefined variable: id_files in H:\wamp\www\php_testing\download.php on line 2
ERORR IN CODE

END ERRORS
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

What are you passing as $id_files?
  • virose
  • Novice
  • Novice
  • virose
  • Posts: 27
  • Loc: florida

Post 3+ Months Ago

Just any file that is in the database. id_file is the Prime key in the database
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Where are you setting the $id_files?
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Also why are you doing:
Code: [ Select ]
$data = @mysql_result($result, 0, "bin_data");
$name = @mysql_result($result, 0, "filename");
$size = @mysql_result($result, 0, "filesize");
$type = @mysql_result($result, 0, "filetype");
  1. $data = @mysql_result($result, 0, "bin_data");
  2. $name = @mysql_result($result, 0, "filename");
  3. $size = @mysql_result($result, 0, "filesize");
  4. $type = @mysql_result($result, 0, "filetype");

...?
Why not:
Code: [ Select ]
$row = mysql_fetch_assoc($result);
$data = $row['bin_data'];
$name = $row['filename'];
$size = $row['filesize'];
$type = $row['filetype'];
  1. $row = mysql_fetch_assoc($result);
  2. $data = $row['bin_data'];
  3. $name = $row['filename'];
  4. $size = $row['filesize'];
  5. $type = $row['filetype'];

Or just use $row['field'] instead of setting variables.
  • virose
  • Novice
  • Novice
  • virose
  • Posts: 27
  • Loc: florida

Post 3+ Months Ago

I was going by this tut http://www.onlamp.com/pub/a/php/2000/09/15/php_mysql.html.

if you have better way please share.

I'm a php hack at best i know the basic's but i have not had time to really learn it.

so the database stuff with php is a little out of my league.
  • virose
  • Novice
  • Novice
  • virose
  • Posts: 27
  • Loc: florida

Post 3+ Months Ago

Ok here's where i am with the download code.

What is the best way to define the var id_files, so the code will just spit the file to the browser for download.

I know now that the variable just needs to be defined, i'm just not sure how to define it and make the if statement still work correctly.

Thanks in advance.
Jason

Code: [ Select ]
 
<?php
 
if ($id_files) {
 
  include "open_db.inc";
 
  $sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
   
  $result = @mysql_query($sql, $db);
 
  $row = mysql_fetch_assoc($result);
  $data = $row['bin_data'];
  $name = $row['filename'];
  $size = $row['filesize'];
  $type = $row['filetype'];
   
  header("Content-type: $type");
  header("Content-length: $size");
  header("Content-Disposition: attachment; filename=$name");
  header("Content-Description: PHP Generated Data");
  echo $data;
} else { echo 'ERORR IN CODE';}
?>
 
 
 
  1.  
  2. <?php
  3.  
  4. if ($id_files) {
  5.  
  6.   include "open_db.inc";
  7.  
  8.   $sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
  9.    
  10.   $result = @mysql_query($sql, $db);
  11.  
  12.   $row = mysql_fetch_assoc($result);
  13.   $data = $row['bin_data'];
  14.   $name = $row['filename'];
  15.   $size = $row['filesize'];
  16.   $type = $row['filetype'];
  17.    
  18.   header("Content-type: $type");
  19.   header("Content-length: $size");
  20.   header("Content-Disposition: attachment; filename=$name");
  21.   header("Content-Description: PHP Generated Data");
  22.   echo $data;
  23. } else { echo 'ERORR IN CODE';}
  24. ?>
  25.  
  26.  
  27.  
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Code: [ Select ]
<?php
$id_files = 17;
if ($id_files) {

include "open_db.inc";

$sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";

$result = @mysql_query($sql, $db);

$row = mysql_fetch_assoc($result);
$data = $row['bin_data'];
$name = $row['filename'];
$size = $row['filesize'];
$type = $row['filetype'];

header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
} else { echo 'ERORR IN CODE';}
?>
  1. <?php
  2. $id_files = 17;
  3. if ($id_files) {
  4. include "open_db.inc";
  5. $sql = "SELECT bin_data, filetype, filename, filesize FROM family_pics WHERE id_file=$id_files";
  6. $result = @mysql_query($sql, $db);
  7. $row = mysql_fetch_assoc($result);
  8. $data = $row['bin_data'];
  9. $name = $row['filename'];
  10. $size = $row['filesize'];
  11. $type = $row['filetype'];
  12. header("Content-type: $type");
  13. header("Content-length: $size");
  14. header("Content-Disposition: attachment; filename=$name");
  15. header("Content-Description: PHP Generated Data");
  16. echo $data;
  17. } else { echo 'ERORR IN CODE';}
  18. ?>
  • virose
  • Novice
  • Novice
  • virose
  • Posts: 27
  • Loc: florida

Post 3+ Months Ago

it's opening itself for download for some reason. instead of pulling the database file.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Try putting:
Code: [ Select ]
 
ob_flush();
 
  1.  
  2. ob_flush();
  3.  

after you echo.

Also, what kind of file_type is it? What kind of files are you trying to show? Images? Video? Text? Dynamic? Any?
  • virose
  • Novice
  • Novice
  • virose
  • Posts: 27
  • Loc: florida

Post 3+ Months Ago

just text files
  • virose
  • Novice
  • Novice
  • virose
  • Posts: 27
  • Loc: florida

Post 3+ Months Ago

yeah that did not change it
  • virose
  • Novice
  • Novice
  • virose
  • Posts: 27
  • Loc: florida

Post 3+ Months Ago

Thanks for all the help guys.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

So, did you get it figured out?
  • virose
  • Novice
  • Novice
  • virose
  • Posts: 27
  • Loc: florida

Post 3+ Months Ago

yeah for the most part i'm just trying to get around globals now on my server i started another topic for it.http://www.ozzu.com/programming-forum/help-getting-this-upload-file-scrip-around-globals-being-off-t97629.html

Post Information

  • Total Posts in this topic: 22 posts
  • Users browsing this forum: No registered users and 127 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.