You could save yourself a whole lot of headaches by putting the files in the
file-system, and storing only the path in the database...

Also, IE and Netscape use different things to populate the filename box on
the download dialog...

One uses Content-disposition header(), and one uses whatever happens to be
at the end of the path part of the URL.

Thus, a goofy path like:

http://wild.net/display.php/goofy.gif?id=42
(Where 42 is a GIF image of Goofy)
actually works.
The web-server and PHP ignore that goofy.gif crap, and the browser is fooled
into thinking you're downloading a static file.

----- Original Message -----
From: "Boget, Chris" <[EMAIL PROTECTED]>
Newsgroups: php.general
Sent: Tuesday, January 09, 2001 4:44 PM
Subject: [PHP] Serving files form DB


> I'm storing files in a mySQL table that looks like this:
>
> | file_name        | varchar(100)        |      | MUL |         | |
> | file_description | text                | YES  |     | NULL    | |
> | file_type        | varchar(50)         |      |     |         | |
> | file_size        | int(10) unsigned    |      |     | 0       | |
> | added_by         | varchar(10)         |      |     |         | |
> | access_types     | text                | YES  |     | NULL    | |
> | access_users     | text                | YES  |     | NULL    | |
> | file_num         | bigint(10) unsigned |      | PRI | 0       |
> auto_increment |
> | bin_data         | blob                |      |     | NULL    | |
>
> the "file_type" field stores the actual data type for the file
> (such as 'application/msword', etc).  To serve the file, I'm
> using the following code:
>
> <script language="php">
>
>   $dbInfo = unserialize( base64_decode( $db_key ));
>   if( is_array( $dbInfo )) {
>
>     $fileQuery  = "SELECT * FROM $dbInfo[table_name] WHERE
>                             file_num=$dbInfo[record_num]";
>     $fileResult = mysql( $dbInfo[db_name], $fileQuery );
>
>     if(( $fileResult ) && ( mysql_errno() == 0 )) {
>       $fileInfo = mysql_fetch_array( $fileResult );
>
>       header( "Content-Disposition: attachment;
> filename=$fileInfo[file_name]" );
>       header( "Content-Description: PHP Generated Data" );
>       header( "Content-type: $fileInfo[file_type];" );
>       header( "Content-length: $fileInfo[file_size]" );
>
>       echo $fileInfo[bin_data];
>
>       flush();
>
>     }
>   }
>
> </script>
>
> Everything is working great.  If I echo the query that is getting
> run, it's correct.  If I echo out the data that is getting passed via
> the header() function, it looks all good.  However, when my
> browser actually tries to download/open the file, everything gets
> all screwed up.  The file name that it says that it's downloading
> is *nothing* like the actual file name and is in fact just a bunch
> of garbage.  If I try to open anything other than a text file, I
> get errors from the application that is getting run (MSWord, say)
> and if I try to save if, the file is corrupt.  There are no spaces or
> NULL characters being printed out by the script.
> What's going on?  What am I doing wrong?
>
> Chris
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to