Forums

PHP

This topic is locked

OFF TOPIC: mkdir questions

Posted 17 May 2002 20:58:50
1
has voted
17 May 2002 20:58:50 Eric Kaiser posted:
I apologize for this off topic question although I develop in UD. Anyhow, I'm trying to check to see if a directory exists, and if it doesn't, create the directy by grabbing the UserID value. It works, but when I hit the page again, I keep getting:
"Warning: MkDir failed (File exists) in /home/newspage/html/admin/welcome_test.ph on line 133". For the life of me I don't know why it errors out like that. I assumed the if statement would read if the directory exists or not, and if it did then it would create the directory. Why is it trying to create the directory??? Here's the code: Oh, and Tim, before you ream me out, I did do a search on the Google Groups, this site, and the Internet trying to find an answer :+)

$UserID = $rsWelcomeUser->Fields("UserID";

# check for directory
$path = dir("/home/newspage/html/users/$UserID";

#check if dir exists
if (!file_exists($path)) {
mkdir("../users/$UserID", 0777);
}
$dir = dir("/home/newspage/html/users/$UserID";
echo "UserID=".$UserID;
$path->close();

Replies

Replied 18 May 2002 14:05:15
18 May 2002 14:05:15 chief monkey replied:
if(!is_dir("/home/newpage/html/users/$UserID")
{
mkdir("/home/newpage/html/users/$UserID";

} else {

print("Directory already exists";
}
you may also need to set the permissions for the directory in which case it's

mkdir("/home/newpage/html/users/$UserID", 0777); or whatever permission you set it to

George


Everybody has got to be somewhere

Reply to this topic