download binary files from database

Ask a Question related to PHP Development, Design and Development.

  1. #1

    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.

    Dux Guest

  2. Similar Questions and Discussions

    1. flash reading binary from a database
      i'm storing videos and images inside a blob in mysql and i need to have flash 8 read the files. right now i'm querying the database using php and...
    2. Inserting binary field into SQL 2000 database
      Hi, I have been trying to upload a .pdf file to a SQL Server 2000 database. I used the dreamweaver MX auto generated code. However, I have the...
    3. Display BInary TIF file from database?
      Is there a way to pull a TIFF binary field from a database and display it in a cold fusion page? I have it working part time with an ASP page and a...
    4. Download binary file to local hard drive
      If this is not the appropriate NG, please help me by telling me where I should post this question. I want to keep a collection of Word Documents...
    5. HOWTO download binary files [EXE & DLL]
      Hi there, I am writing a "Windows Update" type application where via Web Services the client checks with the Server if he needs to download a newer...
  3. #2

    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.

    Dux Guest

  4. #3

    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.
    >

    Sebestyén Dénes Guest

  5. #4

    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.
    >

    Sebestyén Dénes Guest

  6. #5

    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?



    duxbuz Guest

  7. #6

    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?



    duxbuz Guest

  8. #7

    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?
    >
    >
    >

    Sebestyén Dénes Guest

  9. #8

    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?
    >
    >
    >

    Sebestyén Dénes Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139