Re: download not working

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, December 28, 2005 6:10 am, Ross wrote:
> $query= "SELECT * FROM publications WHERE alphabet='a'";
>
>  $result= mysql_query($query);
>    while  ($row = @mysql_fetch_array($result, MYSQL_ASSOC)){
>
>     $row['pdf_size'] = $row['pdf_size']/ 1024;
>  $row['pdf_size']= number_format($row['pdf_size'], 0);
>  $size= $row['pdf_size'];
> $name = str_replace("_", " ", $row['pdf_name']);
> $name = str_replace(".pdf", "", $name);
> $link= $row['content'];

You are echo-ing out these lines whether $_GET['id'] isset or not.

Which means that your PDF isn't starting with:
%PDF3.1
.
.
.

> echo "<span class=\"pdflinks\">$name</span>";
> echo "&nbsp;&nbsp;";
> echo "<span class=\"sizes\">($size kb)</span>";

Your PDF now looks like:
<span class="pdflinks">foo</span>
&nbsp;&nbsp;
<span class="sizes">(25 kb)</span>
%PDF3.1
.
.
.


And that's a pretty corrupt PDF, eh?

For the future:

#1. Always use 'vi' or some kind of text editor to view your "corrupt"
files that PHP sends out.  Invariably you'll smack yourself in the
forehead and be back in business in minutes.

> ob_clean();
> header("Content-length: $pdf_size");
> header("Content-type: $pdf_type");

#2. You can also comment this out until you get it looking right,
rather than go through the process of downloading and opening and all
that.  You'll just see a lot of weird stuff in your browser, but
that's okay.

> header("Content-Disposition: attachment; filename=$pdf_name");

CHANGE THIS TO:

header("Content-type: application/octet-stream");

if you want this to work in ALL browsers.

The Content-Disposition stuff is johnny-come-lately made-up junk that
will NOT be reliable.

To force the filename to be what you want, just take on "/$pdf_name"
to the URL.

I've ranted enough about this before, so you should be able to find
more detail on how to make this really slick with ForceType and
URL-munging.

Search archives for:
"Richard Lynch pathinfo.inc ForceType" and it should come up.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux