如果php中已经存在目录,则不要创建该目录
我正在使用以下命令为每个客户在intranet应用程序上创建一个目录。问题是,如果目录已经存在,我将收到错误:如果php中已经存在目录,则不要创建该目录,php,directory,Php,Directory,我正在使用以下命令为每个客户在intranet应用程序上创建一个目录。问题是,如果目录已经存在,我将收到错误: Warning: mkdir() [function.mkdir]: File exists in C:\server2go\server2go\htdocs\customermgr\administrator\components\com_chronoforms\form_actions\custo m_code\custom_code.php(18) : eval()
Warning: mkdir() [function.mkdir]: File exists in C:\server2go\server2go\htdocs\customermgr\administrator\components\com_chronoforms\form_actions\custo m_code\custom_code.php(18) : eval()'d code on line 11
Failed to create directory...
如果目录已经存在,脚本是否可能不创建目录?是否显示错误
<?php
$customerID = $_GET['cfid'];
/* wherever this particular script will be installed, I want to create a subfolder */
/* Step 1. I need to know the absolute path to where I am now, ie where this script is running from...*/
$thisdir = getcwd();
/* Step 2. From this folder, I want to create a subfolder called "myfiles". Also, I want to try and make this folder world-writable (CHMOD 0777). Tell me if success or failure... */
if(mkdir($thisdir ."/customer-files/$customerID" , 0777))
{
echo "Directory has been created successfully...";
}
else
{
echo "Failed to create directory...";
}
?>
编辑>>>>>>>>>>>>>
我尝试过以下方法,但仍然没有乐趣:-(
只需使用
is_dir
和/或文件_exists
,并且仅在返回false时调用mkdir
[编辑]
等等,我刚才在您的错误消息中发现了一个
eval
。您可以使用is\u dir
和文件\u exists
来查看目录是否存在:
if(file_exists($dirname) && is_dir($dirname)) {
是的。在PHP中使用
\uuu
时完全是随机的。
if(file_exists($dirname) && is_dir($dirname)) {