Re: is_readable(http://.... text file) says not, but I can in browser

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Daniel Brown wrote:
On Sun, Jan 11, 2009 at 13:07, John Allsopp <john@xxxxxxxxxxxxxxxxx> wrote:
Thanks, that worked a treat except I was getting warnings on 404. I looked
around for solutions to that and it appears curl might handle that better,
so I'm currently working on that. Many thanks tho .. let me know if you know
how to stop the warnings :-)

    If you want to stop the warnings and verify that data exists, you
can just modify that code like so:

<?php
   $myFileLast = "http://www.isawit.com/ffindex.php";;
   $theDataLast = (strlen($tmpData = @file_get_contents($myFileLast))
0) ? $tmpData : sprintf("File not found.");
?>

    Then you can modify it to read generated error pages (such as
Apache's stock 404 page) through a simple regexp or other method to
verify that the file is what you expect it to be.


pedantic: really you'd want to check the http status header returned and take the appropriate action depending on what header was returned.

I'm sure there's a way to get the headers from a file_get_contents using one of the stream_get_* functions but can't remember off hand, going to have to look into that at some point. (stream_get_metadata maybe?)

dan raises a good point though; there are loads of responses you can get, and not all of them will be the page you expect; worth giving some thought to.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux