is_file() not working for file beginging with http

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

chintu
Forum Newbie
Posts: 8
Joined: Wed Jul 21, 2004 11:21 am
Contact:

is_file() not working for file beginging with http

Post 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.
lolpix
Forum Commoner
Posts: 41
Joined: Sat Jul 17, 2004 2:20 am

Post 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()
}

?>
chintu
Forum Newbie
Posts: 8
Joined: Wed Jul 21, 2004 11:21 am
Contact:

Post 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?
lolpix
Forum Commoner
Posts: 41
Joined: Sat Jul 17, 2004 2:20 am

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's likely your host has disabled fopen url wrappers. Check the output of [php_man]phpinfo[/php_man]() for those details..
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
chintu
Forum Newbie
Posts: 8
Joined: Wed Jul 21, 2004 11:21 am
Contact:

Post by chintu »

Thankyou all...i will download php 5 and get back
chintu
Forum Newbie
Posts: 8
Joined: Wed Jul 21, 2004 11:21 am
Contact:

Post by chintu »

Isn't there a windows installer for PHP 5.0.0?

I want to upgrade it from 4.3.8.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
chintu
Forum Newbie
Posts: 8
Joined: Wed Jul 21, 2004 11:21 am
Contact:

Post 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!
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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* ;)
chintu
Forum Newbie
Posts: 8
Joined: Wed Jul 21, 2004 11:21 am
Contact:

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can ask [php_man]curl[/php_man] to return the header.. maybe..
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
chintu
Forum Newbie
Posts: 8
Joined: Wed Jul 21, 2004 11:21 am
Contact:

Post by chintu »

urrrgh....curl seems to be so complicated...

will try to read more about caching..dont have much of the idea..

Thanks guys...
Post Reply