filesize() not reading http pages

Hi,

According to the PHP documentation:

it stated that as of php5, filesize supports the reading of remote html
files:

http://php.net/manual/en/function.filesize.php

But I have tried the following:
echo filesize("http://www.yahoo.com/");

It returned me this error:

Warning: filesize() [function.filesize]: stat failed for..blah blah

Anyone have this same problem?

Yes. Im using PHP5

..



Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Eric Layman [ Fr, 02 Februar 2007 00:24 ] [ ID #1615603 ]

Re: filesize() not reading http pages

Eric Layman wrote:
> Hi,
>
> According to the PHP documentation:
>
> it stated that as of php5, filesize supports the reading of remote html
> files:
>
> http://php.net/manual/en/function.filesize.php
>
> But I have tried the following:
> echo filesize("http://www.yahoo.com/");
>
> It returned me this error:
>
> Warning: filesize() [function.filesize]: stat failed for..blah blah
>
> Anyone have this same problem?
>
> Yes. Im using PHP5

Maybe your php has disable the remote file reading, check your php.ini.

--

//Aho
Shion [ Do, 01 Februar 2007 08:31 ] [ ID #1615604 ]

Re: filesize() not reading http pages

HI,

Thakns for the reply.

I have checked this setting in my php.ini

allow_url_fopen = On

It is ON be default.

"J.O. Aho" <user [at] example.net> wrote in message
news:52djb1F1ngqghU1 [at] mid.individual.net...
> Eric Layman wrote:
>> Hi,
>>
>> According to the PHP documentation:
>>
>> it stated that as of php5, filesize supports the reading of remote html
>> files:
>>
>> http://php.net/manual/en/function.filesize.php
>>
>> But I have tried the following:
>> echo filesize("http://www.yahoo.com/");
>>
>> It returned me this error:
>>
>> Warning: filesize() [function.filesize]: stat failed for..blah blah
>>
>> Anyone have this same problem?
>>
>> Yes. Im using PHP5
>
> Maybe your php has disable the remote file reading, check your php.ini.
>
> --
>
> //Aho



Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Eric Layman [ Fr, 02 Februar 2007 01:21 ] [ ID #1615605 ]

Re: filesize() not reading http pages

Eric Layman wrote:

<cut away a bit relevant info, but didn't feel to fix the troubles top
posting causes>


> I have checked this setting in my php.ini
> allow_url_fopen = On

Did read a bit on the online manual,
http://php.net/manual/en/function.filesize.php and it says that you need
a wrapper to be able to read the filesize remotly, see the following
page for more info about wrappershttp://www.php.net/manual/en/wrappers.php

--

//Aho
Shion [ Do, 01 Februar 2007 12:17 ] [ ID #1615613 ]

Re: filesize() not reading http pages

Eric Layman schreef:
> According to the PHP documentation:
>
> it stated that as of php5, filesize supports the reading of remote html
> files:
>
> http://php.net/manual/en/function.filesize.php
>

It also states that you should look in the HTTP wrapper section of the
appendix to see if it's supported by the stat() function. Like this
function, filesize() only works on local files and doesn't support the
HTTP protocol.

If you want to check the size of a remote file, you could do something
as follows:

$fp = fsockopen('www.google.com', 80);
fputs($fp, "HEAD / HTTP/1.0\r\n");
fputs($fp, "Host: www.google.com\r\n\r\n");

$size = 0;
while (!feof($fp)) {
$line = fgets($fp, 1024);
if (preg_match('/content-length:\s*(\d+)/i', $line, $m)) {
$size = $m[1];
break;
}
}
fclose($fp);

print "Size of Google homepage HTML: $size bytes";


JW
Janwillem Borleffs [ Do, 01 Februar 2007 12:19 ] [ ID #1615614 ]

Re: filesize() not reading http pages

Eric Layman wrote:

> Hi,
>
> According to the PHP documentation:
>
> it stated that as of php5, filesize supports the reading of remote
> html files:
>
> http://php.net/manual/en/function.filesize.php
>
> But I have tried the following:
> echo filesize("http://www.yahoo.com/");
>
> It returned me this error:
>
> Warning: filesize() [function.filesize]: stat failed for..blah blah
>
> Anyone have this same problem?
>
> Yes. Im using PHP5

It also says in the manual (you have to read it carefully):

> As of PHP 5.0.0 this function can also be used with *some* URL
> wrappers. Refer to Appendix M for a listing of which wrappers support
> stat() family of functionality.

To summarize, these wrappers support the use of stat():

Filesystem Yes
Socket No
HTTP and HTTPS No
FTP and FTPS Partial [1]
PHP input/output streams php://memory and php://temp only
Compression Streams No [2]
Data (RFC 2397) No
Secure Shell 2 ssh2.ftp only
Audio Streams No
Process Interaction Streams No
http://www.php.net/manual/en/wrappers.php

[1] As of PHP 5.0.0: filesize(), filetype(), file_exists(), is_file(),
and is_dir() elements only. As of PHP 5.1.0: filemtime().
[2] Use the normal file:// wrapper to stat compressed files.

--
Kim André Akerĝ
- kimandre [at] NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
kimandre [ Do, 01 Februar 2007 16:52 ] [ ID #1615620 ]

Re: filesize() not reading http pages

Thank you Kim!


"Kim André Akerĝ" <kimandre [at] NOSPAMbetadome.com> wrote in message
news:52eglbF1o4gaoU1 [at] mid.individual.net...
> Eric Layman wrote:
>
>> Hi,
>>
>> According to the PHP documentation:
>>
>> it stated that as of php5, filesize supports the reading of remote
>> html files:
>>
>> http://php.net/manual/en/function.filesize.php
>>
>> But I have tried the following:
>> echo filesize("http://www.yahoo.com/");
>>
>> It returned me this error:
>>
>> Warning: filesize() [function.filesize]: stat failed for..blah blah
>>
>> Anyone have this same problem?
>>
>> Yes. Im using PHP5
>
> It also says in the manual (you have to read it carefully):
>
>> As of PHP 5.0.0 this function can also be used with *some* URL
>> wrappers. Refer to Appendix M for a listing of which wrappers support
>> stat() family of functionality.
>
> To summarize, these wrappers support the use of stat():
>
> Filesystem Yes
> Socket No
> HTTP and HTTPS No
> FTP and FTPS Partial [1]
> PHP input/output streams php://memory and php://temp only
> Compression Streams No [2]
> Data (RFC 2397) No
> Secure Shell 2 ssh2.ftp only
> Audio Streams No
> Process Interaction Streams No
> http://www.php.net/manual/en/wrappers.php
>
> [1] As of PHP 5.0.0: filesize(), filetype(), file_exists(), is_file(),
> and is_dir() elements only. As of PHP 5.1.0: filemtime().
> [2] Use the normal file:// wrapper to stat compressed files.
>
> --
> Kim Andr Aker
> - kimandre [at] NOSPAMbetadome.com
> (remove NOSPAM to contact me directly)



Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Eric Layman [ Fr, 02 Februar 2007 01:42 ] [ ID #1615624 ]

Re: filesize() not reading http pages

Thanks!

btw, why is there a need for \r\n\r\n appended to the url?


"Janwillem Borleffs" <jw [at] jwscripts.com> wrote in message
news:45c1cca6$0$48643$dbd43001 [at] dr2.euro.net...
> Eric Layman schreef:
>> According to the PHP documentation:
>>
>> it stated that as of php5, filesize supports the reading of remote html
>> files:
>>
>> http://php.net/manual/en/function.filesize.php
>>
>
> It also states that you should look in the HTTP wrapper section of the
> appendix to see if it's supported by the stat() function. Like this
> function, filesize() only works on local files and doesn't support the
> HTTP protocol.
>
> If you want to check the size of a remote file, you could do something as
> follows:
>
> $fp = fsockopen('www.google.com', 80);
> fputs($fp, "HEAD / HTTP/1.0\r\n");
> fputs($fp, "Host: www.google.com\r\n\r\n");
>
> $size = 0;
> while (!feof($fp)) {
> $line = fgets($fp, 1024);
> if (preg_match('/content-length:\s*(\d+)/i', $line, $m)) {
> $size = $m[1];
> break;
> }
> }
> fclose($fp);
>
> print "Size of Google homepage HTML: $size bytes";
>
>
> JW



Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Eric Layman [ Fr, 02 Februar 2007 01:42 ] [ ID #1615625 ]

Re: filesize() not reading http pages

Eric Layman schreef:
> Thanks!
>
> btw, why is there a need for \r\n\r\n appended to the url?
>

Yes, because it's used in a header context (Host), which should be ended
with CRLF characters.


JW
Janwillem Borleffs [ Fr, 02 Februar 2007 12:16 ] [ ID #1616821 ]
PHP » alt.php » filesize() not reading http pages

Vorheriges Thema: php force MP3 'save as' dialog
Nächstes Thema: Centering everything on a page with PHP (or HTML)