You are here: Re: Php Download script problem! « PHP Programming Language « IT news, forums, messages
Re: Php Download script problem!

Posted by Chuck Anderson on 10/13/05 22:52

C16 wrote:

>I was using readfile but found a discussion that showed readfile to be '55%'
>slower than reading by chunks (in the readfile function desc on php.net
>infact). Also tried the header without Content-Transfer-Encoding and many
>other permutations from suggestions found via google but still the same
>result on IE.
>
>"Philip Ronan" <invalid@invalid.invalid> wrote in message
>news:BF743985.39633%invalid@invalid.invalid...
>
>
>>"C16" wrote:
>>
>>
>>
>>>$fp = fopen($filename, "rb");
>>>if ( $fp )
>>>{
>>>$filesize = $file['size'];
>>>
>>>header("Cache-Control: post-check=0, pre-check=0");
>>>header("Expires: 0");
>>>header("Content-Type: " . $xtype);
>>>header("Content-Length: " . (string)($filesize));
>>>header("Content-Transfer-Encoding: binary");
>>>
>>>while ( !feof($fp) )
>>>{
>>>echo(fgets($fp, 4096));
>>>}
>>>fclose($fp);
>>>}
>>>
>>>
>>Assuming $xtype is defined correctly somewhere, I reckon IE is choking on
>>the Content-Transfer-Encoding header. This is a MIME header -- it doesn't
>>belong in an HTTP response at all. Go and read RFC 2616 some time.
>>
>>You don't need to cast $filesize to a string -- PHP will do this for you
>>anyway. And while you're at it, I suggest you replace the while() loop
>>with
>>a readfile() statement instead (<http://uk.php.net/readfile>).
>>
>>Oh, by the way, filesize() is another useful function. That way you can
>>get
>>rid of the fopen and fclose instructions altogether.
>>
>>
Here's what works for me. I haven't tested your case with IE but you
might give it a try.

header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Length: ' . filesize($file));

// to download
header('Content-Disposition: attachment; filename=' . basename($file));

// to open in browser
//header('Content-Disposition: inline; filename=' . basename($file));

readfile($file);

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************

 

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

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