0

我正在尝试验证:我尝试创建的文件夹是否存在。当然,我收到一条消息......一条错误消息:/告诉我它确实如此!(如果它不存在,则没有错误消息,并且一切都按计划进行)。

它输出此错误消息

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

我使用的当前代码是这个:

$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/>';
}

我最近添加了中间部分(我不知道这是否会产生影响)。以“function ftp_directory_exists($ftp, $dirPath)”开头的那个

4

2 回答 2

1

用于file_exists()检查文件/目录是否存在:

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

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

}
于 2013-07-24T16:00:06.503 回答
1

您添加的函数 ftp_directory_exists 不会对您的代码产生任何影响,因为它从未被调用...

你可能会尝试这样的事情(未测试......):

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

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

echo '<br/>'.$dirPath . (($dirExists)? "" : "DO NOT") . " exists".'<br/>';
于 2013-07-24T16:08:55.743 回答