download binary files from database

This is a discussion on download binary files from database within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I have used some example code to create a database in MySQL and using php I can add binary files ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-04-2003
Dux
 
Posts: n/a
Default download binary files from database

I have used some example code to create a database in MySQL and using
php I can add binary files to the database. I was under the impression
that I would be able to download the files with the source code
provided, but am having trouble doing that.

<?php
if ($id_files) {
include "./include/open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM tbl_Files
WHERE id_files=$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;
}
?>

I thought I would be greeted with a dialog box asking me where i want to
save my file.

Am I getting the wrong impression?

How would I go about downloading the data from database?

Thanks.

Reply With Quote
  #2 (permalink)  
Old 07-04-2003
Sebestyén Dénes
 
Posts: n/a
Default Re: download binary files from database

Maybe the filetype is incorrect, I suggest to use application/octet-stream.
I could get it with this.

"Dux" <dux@nospam.com> wrote in message
news:be3gl6$707$1@titan.btinternet.com...
> I have used some example code to create a database in MySQL and using
> php I can add binary files to the database. I was under the impression
> that I would be able to download the files with the source code
> provided, but am having trouble doing that.
>
> <?php
> if ($id_files) {
> include "./include/open_db.inc";
> $sql = "SELECT bin_data, filetype, filename, filesize FROM tbl_Files
> WHERE id_files=$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;
> }
> ?>
>
> I thought I would be greeted with a dialog box asking me where i want to
> save my file.
>
> Am I getting the wrong impression?
>
> How would I go about downloading the data from database?
>
> Thanks.
>



Reply With Quote
  #3 (permalink)  
Old 07-05-2003
duxbuz
 
Posts: n/a
Default Re: download binary files from database

"Sebestyén Dénes" wrote:

> Maybe the filetype is incorrect, I suggest to use application/octet-stream.
> I could get it with this.
>
> "Dux" <dux@nospam.com> wrote in message
> news:be3gl6$707$1@titan.btinternet.com...
> > I have used some example code to create a database in MySQL and using
> > php I can add binary files to the database. I was under the impression
> > that I would be able to download the files with the source code
> > provided, but am having trouble doing that.
> >
> > <?php
> > if ($id_files) {
> > include "./include/open_db.inc";
> > $sql = "SELECT bin_data, filetype, filename, filesize FROM tbl_Files
> > WHERE id_files=$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;
> > }
> > ?>
> >
> > I thought I would be greeted with a dialog box asking me where i want to
> > save my file.
> >
> > Am I getting the wrong impression?
> >
> > How would I go about downloading the data from database?
> >
> > Thanks.
> >


Thanks for help, but....

Still not getting a file to download. My database output looks like this:

Filename Type Size
Description

putty.exe application/octet-stream 356352 Putty
Application, ssh client for win32 (Download )
readme.txt text/plain 9851
mozilla readme ( Download )

So the type is application/octet-stream, but still no download.

What am I missing?



Reply With Quote
  #4 (permalink)  
Old 07-06-2003
Sebestyén Dénes
 
Posts: n/a
Default Re: download binary files from database

Is the case of the field-name OK? Because I think php is case-sensitive for
getting variables from a database, and I can't think anything else that can
cause an error like this...
Maybe for debugging try to change header() to echo to see if it's right.

"duxbuz" <webmaster@duxbuz.com> wrote in message
news:3F06C69B.4D0D2F5C@duxbuz.com...
>
> Thanks for help, but....
>
> Still not getting a file to download. My database output looks like this:
>
> Filename Type Size
> Description
>
> putty.exe application/octet-stream 356352 Putty
> Application, ssh client for win32 (Download )
> readme.txt text/plain 9851
> mozilla readme

( Download )
>
> So the type is application/octet-stream, but still no download.
>
> What am I missing?
>
>
>



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:43 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0