Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #4753
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
| Newsgroups | comp.lang.php |
| Subject | Re: Headers in fpassthru() output |
| Date | Tue, 07 Feb 2012 09:48:37 +0100 |
| Lines | 64 |
| Message-ID | <9pc6r5FtnsU1@mid.uni-berlin.de> (permalink) |
| References | <jgq2u7$unn$1@news1.cse.ohio-state.edu> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de cw34qf7h3k93YwR9S6QVhQsIyGisKJf2kSL/rX8ntYR0ac620= |
| User-Agent | Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.24) Gecko/20111101 Thunderbird/3.1.16 |
| In-Reply-To | <jgq2u7$unn$1@news1.cse.ohio-state.edu> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.php:4753 |
Show key headers only | View raw
Am 07.02.2012 03:40, schrieb Michael T. Davis:
> So far, I've tested a call to fopen followed by a call to fpassthru
> on a remote (http://...) JPEG file with PHP v4.4.7 in the "OSU Web Server"
> running under OpenVMS V8.3 on an Alpha, and with PHP v5.3.4 in Apache v2.2.17
> running under Mac OS X v10.6.8. The JPEG file is served by a Webcam. The
> documentation (on php.net) for "http://" says the stream opened by fopen only
> provides access to the body of the response. Why is it, then, that when I
> call on fpassthru for the (JPEG URL) stream, I see the headers included in the
> data returned?
>
> The code looks basically like this:
>
> $image = fopen ( "http://...jpg", "r" );
> foreach ( $http_response_header as $header )
> {
> echo "{$header}\r\n";
> }
> echo "\r\n";
> fpassthru ( $image );
> fclose ( $image );
>
> With the above, the headers are clearly visible at the beginning of the data,
> rendering a lot of meaningless code in the browser window, rather than an
> actual image. One work-around I've developed is...
>
> $image = fopen ( "http://...jpg", "r" );
> $inHeaders = 1;
> while ( $inHeaders && ! feof ( $image ) )
> {
> $line = fgets ( $image );
> echo $line;
> $inHeaders = ( $line != "\r\n" );
> }
> if ( ! feof ( $image ) )
> fpassthru ( $image );
> fclose ( $image );
>
> Can anyone explain why I'm seeing behavior counter to the documentation with
> "fopen ( 'http://...' )" and "fpassthru (...)"? (FWIW, the purpose of the
> code is to "proxy" a Webcam image that isn't directly available, so that as
> far as the browser is concerned, the image is served by the web server
> hosting this PHP code.)
>
> Thanks,
> Mike
I can't confirm the problem - no headers here:
strobel@s114-intel:~> php -a
Interactive shell
php > $h = fopen('http://php.net','r');
php > fpassthru ($h);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>PHP: Hypertext Preprocessor</title>
...
Tested on an ubuntu 10.04 server.
/Str.
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Headers in fpassthru() output DAVISM@ecr6.ohio-state.edu (Michael T. Davis) - 2012-02-07 02:40 +0000
Re: Headers in fpassthru() output "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-02-07 09:48 +0100
Re: Headers in fpassthru() output "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-02-07 09:56 +0100
Re: Headers in fpassthru() output "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2012-02-07 10:34 +0100
Re: Headers in fpassthru() output DAVISM@ecr6.ohio-state.edu (Michael T. Davis) - 2012-02-07 16:36 +0000
Re: Headers in fpassthru() output "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-02-07 17:50 +0100
Re: Headers in fpassthru() output DAVISM@ecr6.ohio-state.edu (Michael T. Davis) - 2012-02-07 17:35 +0000
Re: Headers in fpassthru() output "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-02-08 11:38 +0100
Re: Headers in fpassthru() output "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2012-02-08 10:10 +0100
csiph-web