please help meWarning: mkdir() [function.mkdir]: File exists in..xxxxx/register.php. yeah yeah what is wrong here is my code:
btw im at xxxxx/register.php

$documentroot = $_SERVER['DOCUMENT_ROOT'];
if(mkdir($documentroot ."/". $username , 0777))
{
$profile = $documentroot ."/". $username ."/index.php" ;
$filegettingcopy = $documentroot ."/xxxxx/index.php" ;
if (copy($filegettingcopy, $profile))
{echo "<br> You can access your profile at <a href=\"http://www.mysite.com/" . $username. "\">www.mysite.com/$username</a> <br>";
}}
else
{
   echo "There was a problem. Your profile was not made. ";
}

those few lines of code are supposed to make the directory of the username of the person who registering chooses....
AND copy the index.php file from the directory xxxxx into the new "username" directory.
im getting the error and obviously there was a problem.. your profile was not made. what am i doing incorectly?

Recommended Answers

All 3 Replies

Hey.

As the Warning says, the file or directory you are trying to create appears to already exist.
Have you verified that this is not the case?

You should use the file_exists function on your path before trying to create it, to make sure it actually needs to/can be created.

P.S.
Check out Indenting!

You can't create a directory that already exists.
If I were you, I would add another if clause the checks if the directory exists.
If it does, it can do nothing or delete its contents, if it doesn't create it.

For instance,

$dir = $docroot . '/' . $username;
if (!file_exists ( $dir )) {
mkdir($dir);
}

thank you thank you thank you. for 1 i didnt know it had actually made the directory all ready and for two... i didnt know that meant that it had. and also. thank u for the directory check. it works!!!!!!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.