0

Anyone know what I'm doing wrong here? I'm trying to get this code to work so that if a directory exists.. the mkdir() function is bypassed (so i dont get an error) but it seems that no matter what I throw in my is_dir() function it always hops down to the else.

$user = $_POST["user"];
$dirname = "./cp/userfiles/{$user}/"; 

if (is_dir($dirname)) {    
echo "The directory {$user} exists";    
} else {    
mkdir("userfiles/{$user}", 0777);    
echo "The directory {$user} was successfully created.";    
}

Edited by Encrypted: n/a

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Encrypted
0

Try the following:

$user = stripslashes($_POST["user"]);
$dirname = "./cp/userfiles/$user/"; 
 
if (is_dir($dirname)) {    
echo "The directory $user exists";    
} else {    
mkdir("userfiles/$user", 0777);    
echo "The directory $user was successfully created.";    
}
0

Nope, that didn't help. The $_post["user"] returns a user id num from my database, so that shouldn't be the problem. I'll play around with the dirname a bit to see if it's possibly going into the wrong directory.

Edit: I thought i tried editing that already, but that was the problem ^. Maybe I didn't refresh the page when I went to test it out. Thanks for the help though.

Edited by Encrypted: n/a

0

The $_post["user"] returns a user id num from my database

Then perhaps rename the array to the variable $user and change it elsewhere in the script because using the $_POST array for database retrieval could be your problem and it's insecure too as $_POST is a global array (not good).

0

Then perhaps rename the array to the variable $user and change it elsewhere in the script because using the $_POST array for database retrieval could be your problem and it's insecure too as $_POST is a global array (not good).

No no, that's not what I'm doing. I'm actually copying a variable called $uid into a hidden form input and then using $_POST to retrieve it from the form.

So $uid is being called from the database with a mysql_query.

Edited by Encrypted: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.