Page 1 of 1
I there any way to Verify directory on intenet
Posted: Wed Aug 12, 2009 12:49 am
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
Re: I there any way to Verify directory on intenet
Posted: Wed Aug 12, 2009 1:04 am
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";
}
Re: I there any way to Verify directory on intenet
Posted: Wed Aug 12, 2009 2:05 am
by gaurav10in
does it work for web based servers.
i think it only works for local directories.
Re: I there any way to Verify directory on intenet
Posted: Wed Aug 12, 2009 2:19 am
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"...
Re: I there any way to Verify directory on intenet
Posted: Wed Aug 12, 2009 2:41 am
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.
Re: I there any way to Verify directory on intenet
Posted: Wed Aug 12, 2009 2:54 am
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.
Re: I there any way to Verify directory on intenet
Posted: Wed Aug 12, 2009 4:18 am
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)
Re: I there any way to Verify directory on intenet
Posted: Wed Aug 12, 2009 5:03 am
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.
Re: I there any way to Verify directory on intenet
Posted: Wed Aug 12, 2009 7:05 am
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.
Re: I there any way to Verify directory on intenet
Posted: Wed Aug 12, 2009 8:23 am
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).