You are here: Re: [PHP] download not working « PHP « IT news, forums, messages
Re: [PHP] download not working

Posted by "Richard Lynch" on 12/30/05 22:15

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация