Page 1 of 2
is_file() not working for file beginging with http
Posted: Wed Jul 21, 2004 11:21 am
by chintu
I am novice PHP scripter, just coding my second one..
I am trying to open a file which is present on other server. I use is_file() fucntion to make sure if the file is present.
Problem is that, is_file() is not working for files starting with http://
I checked for path and file everything seems to be correct. Also when i try to fopen() the file removing is_file(), it works. But i need to use is_file() before opening.
Any suggestions?
Thanking you in advance.
Posted: Wed Jul 21, 2004 11:54 am
by lolpix
How about...
Code: Select all
<?php
if ($handle = fopen("http://www.example.com/", "r"))
{
// Is an exsiting file you can access with fopen()
}
?>
Posted: Wed Jul 21, 2004 12:02 pm
by chintu
Thanks for reply lolpix..but
well...there are several files on the server and i check if the file exits..if it does i provide a link to it on the page...thats what i am suppose to do..
i cant check by opening each and every file.
suggestions?
Posted: Wed Jul 21, 2004 12:13 pm
by lolpix
I would hope that is the sort of thing most server admins would be trying to prevent people from doing! Do you have access to both servers?
Posted: Wed Jul 21, 2004 12:39 pm
by feyd
It's likely your host has disabled fopen url wrappers. Check the output of [php_man]phpinfo[/php_man]() for those details..
Posted: Wed Jul 21, 2004 12:47 pm
by markl999
From the
PHP Manual:
Tip: As of PHP 5.0.0 this function can also be used with some URL wrappers.
So you'de need PHP5 to use is_file() on a remote url/file.
Posted: Wed Jul 21, 2004 1:18 pm
by chintu
Thankyou all...i will download php 5 and get back
Posted: Wed Jul 21, 2004 1:26 pm
by chintu
Isn't there a windows installer for PHP 5.0.0?
I want to upgrade it from 4.3.8.
Posted: Wed Jul 21, 2004 1:30 pm
by markl999
I wouldn't install PHP5 *just* to get this is_file() to work, that's a bit drastic. You might end up with more problems than you started with.
Posted: Wed Jul 21, 2004 1:39 pm
by chintu
Than what do suggest markl999?
Any other way out to solve my problem?
PHP forum are real good...everyone replies promptly..hussh...where could i have been if not here...
Thanks!
Posted: Wed Jul 21, 2004 1:45 pm
by markl999
You could do something like:
Code: Select all
$thefile = @file_get_contents('http://foo.com/whatever.html');
if($thefile === FALSE){
//the file doesn't exist (or there was some other error)
} else {
//you got the file, it's content is in $thefile
}
*shrug*

Posted: Wed Jul 21, 2004 3:16 pm
by chintu
Thanks...That works markl999...but i have to check for existence of 100's of pdf files....and if it does exists i generate links on to webpage
Its working real slow..any other option ..or how can i make it work fast..
Anticipating reply...
Posted: Wed Jul 21, 2004 3:18 pm
by feyd
you can ask [php_man]curl[/php_man] to return the header.. maybe..
Posted: Wed Jul 21, 2004 3:25 pm
by markl999
Yeah, there's a few ways to do it, but all of them involve you having to actually get the info from the server. You could use caching i suppose and only do a full check ever hour (or whenever) ... but it depends on the specifics of your app.
Posted: Wed Jul 21, 2004 3:28 pm
by chintu
urrrgh....curl seems to be so complicated...
will try to read more about caching..dont have much of the idea..
Thanks guys...