Re: is_readable(http://.... text file) says not, but I can in browser
| From: | Nathan Rixham | Date: | Sun, 11 Jan 2009 18:42:25 +0000 |
| Subject: | Re: is_readable(http://.... text file) says not, but I can in browser | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-286043@lists.php.net to get a copy of this message | ||
Daniel Brown wrote:
On Sun, Jan 11, 2009 at 13:07, John Allsopp <john@johnallsopp.co.uk> wrote: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.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, youcan 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 asApache's stock 404 page) through a simple regexp or other method to verify that the file is what you expect it to be.