尝试验证使用PHP动态创建的文件夹

I am trying validate: whether or not the folder I am attempting to create exists. Sure, I get a message... an error message :/ telling me it does! (if it doesn't exist, no error message, and everything goes as planned).

It outputs this error message

Directory exists

Warning: mkdir() [function.mkdir]: File exists in /home/***/public_html/***/formulaires/processForm-test.php on line 75

UPLOADS folder has NOT been created

The current code I use is this one:

$dirPath = $_POST['company'];  

if(is_dir($dirPath))
  echo 'Directory exists';
else
  echo 'directory not exist';

function ftp_directory_exists($ftp, $dirPath) 
{ 
    // Get the current working directory 
    $origin = ftp_pwd($ftp); 

    // Attempt to change directory, suppress errors 
    if (@ftp_chdir($ftp, $dirPath)) 
    { 
        // If the directory exists, set back to origin 
        ftp_chdir($ftp, $origin);    
        return true; 
    } 

    // Directory does not exist 
    return false; 
} 


$result = mkdir($dirPath, 0755);  
if ($result == 1) {  
    echo '<br/>'.$dirPath . " has been created".'<br/>';
} else {  
    echo '<br/>'.$dirPath . " has NOT been created".'<br/>';
}

I added the middle part recently (I don't know if that would even have an impact). The one that starts off with "function ftp_directory_exists($ftp, $dirPath)"

Use file_exists() to check if a file / directory exists:

if(!file_exists('/path/to/your/directory')){

//yay, the directory doesn't exist, continue

}

The function ftp_directory_exists you added won't have any impact on your code as it is never called...

You might tried something like this (not tested...) :

$dirPath = $_POST['company'];  
$dirExists = is_dir($dirPath);

if(!dirExists)
    $dirExists = mkdir($dirPath, 0755);  

echo '<br/>'.$dirPath . (($dirExists)? "" : "DO NOT") . " exists".'<br/>';