Forum Moderators: coopster
Basically I am trying to replicate the ASP code :
# # #
function doesfolderexist(foldername)
Set dfs=Server.CreateObject("Scripting.FileSystemObject")
If dfs.FolderExists(foldername) = true Then
doesfolderexist = true
Else
doesfolderexist = false
End If
set dfs=nothing
end function
# # #
So far I have looked into is_dir, file_exists etc but have been having some trouble with the path specified :
// to check to see if directory exists
//$path = dirname($_SERVER['PHP_SELF']); - not working? why not?
$path = 'C:\Inetpub\wwwroot\ba\d\sitex'; //works
$folder = 'graphics';
$test = $path.'/'.$folder;
print '<br>Path to Directory = ' . $test;
if (is_dir ($test)) {
print "<br><br>++Dir exists" . '[' . $test .']';
}
else {
print "<br><br>--Dir doesn't exist" . '[' . $test .']';
}
The code above will only find the graphics folder if the path is hard coded from absolute. If I try to use something like PHP_SELF or ./ in a path it doesn't work.
So what am I doing wrong? Should I be looking for the absolute path and then going to find directories?
If you can help I would be grateful - cheers - Ed
----------
// to see if directory exists
$dir = 'graphics';
if (file_exists($dir) && is_dir($dir)) {
print $dir . ' is a directory!';
}
else {
print $dir . ' is not directory';
}
----------
And it works fine... strange. Now I can look through all the directories in the main directory and see if they exist or not. But what I don't understand is why this should work when the previous method I tried didn't?
Could do with some help understanding this ... cheers if you can explain (I've been reading the php.net manual and a Core php manual but still don't understand)
// to check to see if directory exists
$path = dirname($_SERVER['PHP_SELF']); - not working? why not?
exit("Path is: $path");
// $path = 'C:\Inetpub\wwwroot\ba\d\sitex'; //works
$folder = 'graphics';
$test = $path.'/'.$folder;
print '<br>Path to Directory = ' . $test;
if (is_dir ($test)) {
print "<br><br>++Dir exists" . '[' . $test .']';
}
else {
print "<br><br>--Dir doesn't exist" . '[' . $test .']';
}