Re: Headers in fpassthru() output [message #176940 is a reply to message #176938] |
Tue, 07 February 2012 16:36 |
DAVISM
Messages: 3 Registered: February 2012
Karma:
|
Junior Member |
|
|
In article <jgqr6d$dlh$1(at)dont-email(dot)me>,
=?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=<alvaro(dot)NOSPAMTHANX(at)demogracia(dot)com(dot)invalid> writes:
> El 07/02/2012 3:40, Michael T. Davis escribió/wrote:
>> 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.
>
> I don't know for sure what manual page you are quoting (you just point
> to the PHP site) but the full quote at the page for the HTTP wrapper [1] is:
>
> «The stream allows access to the body of the resource; the headers are
> stored in the $http_response_header variable.»
>
> ... and that's exactly what you are doing: printing the values of the
> $http_response_header variable [2].
>
> [1] http://es2.php.net/manual/en/wrappers.http.php
> [2] http://es2.php.net/manual/en/reserved.variables.httpresponseheader.php
I'm referencing the English version of the documentation that you
are citing.
>
>
>
>
>
>> 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 (...)"?
>
> Neither http://es.php.net/manual/en/function.fopen.php nor
> http://es.php.net/fpassthru claim that $http_response_header should not
> get populated...
I didn't claim that $http_response_header was invalid. As I
mentioned in the parenthetical at the end of the original post, I'm trying
to serve the JPEG image of a network Webcam from the host where I have the
PHP script, in order to make it appear as if the JPEG image comes from the
PHP-running host. This means I need to send the headers that come from
the response of the Webcam to the browser. I can certainly leverage
$http_response_header and push the contents to the broswer, but if I do
that--given the behavior I'm seeing--it seems I would still need to parse
the headers from the fopen call and "drop them on the floor" before sending
the "actual" body/image of what comes from the Webcam. If I'm going to
parse the headers, I figured I might as well do something with them, which
is why the work-around doesn't call on $http_response_header.
>
>
>
> --
> -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
> -- Mi sitio sobre programación web: http://borrame.com
> -- Mi web de humor satinado: http://www.demogracia.com
> --
Regards,
Mike
|
|
|