I there any way to Verify directory on intenet

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

Post Reply
gaurav10in
Forum Newbie
Posts: 4
Joined: Wed Aug 12, 2009 12:45 am

I there any way to Verify directory on intenet

Post by gaurav10in »

I am setting up a website.
I need to find whether a directory has been created on my content web site or not.

Can anyone please tell me how to do this.
I was able to find the file by using fOpen() API.

I am in urgent need.

Thanks and Regards,
Gaurav Arora
User avatar
neuroxik
Forum Commoner
Posts: 25
Joined: Tue Aug 11, 2009 10:32 pm

Re: I there any way to Verify directory on intenet

Post by neuroxik »

You can use the is_dir() function.

Example:

Code: Select all

$dir_name = "[b]some_directory_name_here[/b]";
 
if(is_dir($dir_name)) {
    // dir exists, do your thing here
    echo "Directory ".$dir_name." exists ";
}
else {
    // dir does NOT exist
    echo "Directory ".$dir_name." does not exist";
}
 
Last edited by neuroxik on Wed Aug 12, 2009 8:30 am, edited 1 time in total.
gaurav10in
Forum Newbie
Posts: 4
Joined: Wed Aug 12, 2009 12:45 am

Re: I there any way to Verify directory on intenet

Post by gaurav10in »

does it work for web based servers.
i think it only works for local directories.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: I there any way to Verify directory on intenet

Post by requinix »

On your site? Then write some code for that site that checks for a directory and poll that.

Otherwise there's no way to tell if something is a directory or not remotely. You just can't know.

Wow... I actually said "right" instead of "write"...
Last edited by requinix on Wed Aug 12, 2009 7:02 am, edited 1 time in total.
User avatar
neuroxik
Forum Commoner
Posts: 25
Joined: Tue Aug 11, 2009 10:32 pm

Re: I there any way to Verify directory on intenet

Post by neuroxik »

As tasairis said, it's meant for your server (whether public or not).

If you take images/ (<- links to forums.devnetwork's images dir) for example, it's a dir, but it will return FALSE on is_dir, yet it is a dir. There'S also the fact that most dirs will be restricted, either via htaccess or by having an index file in the dir.
Last edited by neuroxik on Wed Aug 12, 2009 4:16 am, edited 1 time in total.
gaurav10in
Forum Newbie
Posts: 4
Joined: Wed Aug 12, 2009 12:45 am

Re: I there any way to Verify directory on intenet

Post by gaurav10in »

Actually i am trying something like this:

//if directory exists on another server
if(is_dir("http://abc.com/accounts/"))
{
echo "Hello";
}
else
{
//do not allow user to proceed
exit("Error while trying");
}

It always shows me the Error message: "Error while trying".

Anyone please tell me its urgent.
Thanks for your help.
User avatar
neuroxik
Forum Commoner
Posts: 25
Joined: Tue Aug 11, 2009 10:32 pm

Re: I there any way to Verify directory on intenet

Post by neuroxik »

As I said in the post above:
neuroxik wrote:it's a dir, but it will return FALSE on is_dir
Therefore, you get the (in your case you echo en error) error.

You need to play with local files (public or not)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: I there any way to Verify directory on intenet

Post by onion2k »

neuroxik wrote:You need to play with local files (public or not)
If a site is using mod_rewrite for URL rewriting then there might not be a local directory, yet the URL "directory" will still exist. example.com/images/ could easily be mapped to /img ... creating a new directory called /images would consequently never work on website (or would break the website, depending whether or not the rewrite rule is set up with the L (last) directive). I think that is the issue that the poster is trying to work out - he needs to check if the website "directory" exists, not just whether there's an actual directory.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: I there any way to Verify directory on intenet

Post by requinix »

One thing you can test for is if requesting the path without the trailing slash ends in a redirect to the same URL but with the slash. Apache, for one, does this on real directories.

Next, more complicated, is to get the page, then look for links in it that suggest the path is a directory. Like if you get /images and find that there's a "/images/picture.jpg", you can guess that /images can be treated as a directory.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: I there any way to Verify directory on intenet

Post by onion2k »

tasairis wrote:Next, more complicated, is to get the page, then look for links in it that suggest the path is a directory. Like if you get /images and find that there's a "/images/picture.jpg", you can guess that /images can be treated as a directory.
No, you really can't. It's easy to rewrite URLs with mod_rewrite so that a directory like /img appears in every regard to be /images to the user. Directing /images/picture.jpg to /img/picture.jpg is trivial (and quite common).
Post Reply