file upload to database help

  • virose
  • Novice
  • Novice
  • No Avatar
  • Joined: Jul 20, 2005
  • Posts: 27
  • Loc: florida
  • Status: Offline

Post May 4th, 2009, 8:57 am

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
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 4th, 2009, 8:57 am

  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post May 4th, 2009, 9:48 am

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. ?>
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jan 14, 2009
  • Posts: 162
  • Loc: India-Kolkata
  • Status: Offline

Post May 5th, 2009, 11:23 pm

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!!
Wrap Up your Big Url | Mariana World Community
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post May 6th, 2009, 2:00 pm

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.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • virose
  • Novice
  • Novice
  • No Avatar
  • Joined: Jul 20, 2005
  • Posts: 27
  • Loc: florida
  • Status: Offline

Post May 7th, 2009, 9:18 am

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
  • No Avatar
  • Joined: Jul 20, 2005
  • Posts: 27
  • Loc: florida
  • Status: Offline

Post May 7th, 2009, 10:45 am

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
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post May 7th, 2009, 3:05 pm

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:
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • virose
  • Novice
  • Novice
  • No Avatar
  • Joined: Jul 20, 2005
  • Posts: 27
  • Loc: florida
  • Status: Offline

Post May 7th, 2009, 6:05 pm

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
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post May 7th, 2009, 6:38 pm

What are you passing as $id_files?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • virose
  • Novice
  • Novice
  • No Avatar
  • Joined: Jul 20, 2005
  • Posts: 27
  • Loc: florida
  • Status: Offline

Post May 7th, 2009, 7:06 pm

Just any file that is in the database. id_file is the Prime key in the database
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post May 7th, 2009, 7:11 pm

Where are you setting the $id_files?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post May 7th, 2009, 7:21 pm

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.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • virose
  • Novice
  • Novice
  • No Avatar
  • Joined: Jul 20, 2005
  • Posts: 27
  • Loc: florida
  • Status: Offline

Post May 7th, 2009, 7:37 pm

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
  • No Avatar
  • Joined: Jul 20, 2005
  • Posts: 27
  • Loc: florida
  • Status: Offline

Post May 11th, 2009, 5:35 pm

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
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post May 11th, 2009, 5:58 pm

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. ?>
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 11th, 2009, 5:58 pm

Post Information

  • Total Posts in this topic: 22 posts
  • Users browsing this forum: No registered users and 157 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.