RE: [PHP] Downloading MySQL Files

From: Stephen Craton (webmaster_at_melchior.us)
Date: 11/11/03


To: "'John Hicks'" <johnlist@gulfbridge.net>
Date: Mon, 10 Nov 2003 20:36:38 -0500

Thanks for the help, I found the problem. Turns out nothing was in the
blobs, it just wasn't uploading. Fixed now though. Thanks again!

 
Thanks,
Stephen Craton
http://www.melchior.us -- http://www.melchior.us/portfolio
 

-----Original Message-----
From: John Hicks [mailto:johnlist@gulfbridge.net]
Sent: Monday, November 10, 2003 8:31 PM
To: Stephen Craton
Subject: Re: [PHP] Downloading MySQL Files

On Monday 10 November 2003 08:07 pm, Stephen Craton
wrote:
> I have a database which keeps some normal files in
> LONGBLOBS. I then call up a file called download.php
> to retrieve the file from the database, echo out
> it’s contents, and it’s type, and all that so they
> download it.

> However, if the user clicks the
> download link, they download the actual download.php
> file and if they open it, it’s blank.

Here is where you begin to get confused. The output of
your php page will be called download.php, no matter
what is in it. Obviously they are not downloading the
contents of your download.php file since that file is
obviously not blank. Rather they are downloading the
output generated by your download.php, which is
nothing.

> I’ve attached
> the code to download.php. Any ideas why this is
> happening and how to fix it?

Are you getting any PHP errors? (Check your log.)

Are you getting any MySQL errors? (You should include
an error check in your statements.)

If no to the above, then break the program down into
parts and output debug statements. E.g. echo that the
if conditional is being executed, echo the contents of
the first SQL statement, echo the variables of the
output, etc.

Hope this helps.

--John

> <?php
>
> if (isset($HTTP_GET_VARS['id'])) {
>
>
> include('Connections/default.php');
>
>
> mysql_select_db($database_default, $default);
>
> $id =
> $HTTP_GET_VARS['id'];
>
>
>
> $query = "SELECT *
> FROM files WHERE id='$id'";
>
> $result =
> mysql_query($query, $default);
>
> $row =
> mysql_fetch_array($result);
>
> $new =
> $row['downloads'] + 1;
>
> $query = "UPDATE
> files SET downloads='$new' WHERE id='$id'";
>
> $result =
> mysql_query($query, $default);
>
>
>
> $type =
> $row["ftype"];
>
> $name =
> $row["fname"];
>
> $size =
> $row["fsize"];
>
> $id = $row["id"];
>
> $data =
> urldecode($row["fdata"]);
>
>
>
>
> header("Content-type: $type");
>
>
> header("Content-length: $size");
>
>
> header("Content-Disposition: attachment;
> filename=$name");
>
>
> header("Content-Description: PHP Generated Data");
>
>
>
> echo $data;
>
> exit();
>
> }
>
> ?>
>
>
>
>
>
> Thanks,
>
> Stephen Craton
>
> HYPERLINK
> "http://www.melchior.us"http://www.melchior.us --
> HYPERLINK
> "http://www.melchior.us/portfolio"http://www.melchio
>r.us/portfolio
>
>
>
>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system
> (http://www.grisoft.com). Version: 6.0.532 / Virus
> Database: 326 - Release Date: 10/27/2003

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.532 / Virus Database: 326 - Release Date: 10/27/2003
 
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.532 / Virus Database: 326 - Release Date: 10/27/2003
 


Relevant Pages

  • Re: My slide show transitions and custom animation tools arent wo
    ... Echo ... I do use Norton Antivirus and regularly update it. ... >> I'd also suggest downloading and running AdAware ... I am looking at System Information. ...
    (microsoft.public.powerpoint)
  • Re: [SLE] Setting a script to automatically download a file from nai.com ftp site?
    ... You will need to put it in a script file and run it from cron. ... echo "Retrieving update list" ... echo "downloading $FTPDIR$DATNAME - please wait" ...
    (SuSE)
  • Re: Reset Free Trials
    ... Defending our democracy', ... >> Does anyone know how and where you can reset the file that ... > downloading 'free trails' and then you would have a year and a month to ... > Checked by AVG anti-virus system. ...
    (microsoft.public.windowsxp.general)
  • Re: Reset Free Trials
    ... > Does anyone know how and where you can reset the file that ... downloading 'free trails' and then you would have a year and a month to ... Outgoing mail is certified Virus Free. ... Checked by AVG anti-virus system. ...
    (microsoft.public.windowsxp.general)
  • Re: Can I limit number of messages to be downloaded
    ... DO NOT turn on the auto compact and or delete functions. ... For instance if I start downloading today, ... Checked by AVG anti-virus system. ... Outgoing mail is certified Virus Free. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)