我正在使用以下内容在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()'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...";
}
?>编辑>>>>>>>>>>>>>
我试过以下几种方法,但还是不满意:-(
<?php
$customerID = $_GET['cfid'];
$directory = "/customer-files/$customerID";
if(file_exists($directory) && is_dir($directory)) {
}
else {
/* 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...";
} }
?>发布于 2012-03-25 06:23:33
只需使用is_dir和/或file_exists,并且仅当它们返回false时才调用mkdir。
编辑
等等,我是不是在你的错误信息里发现了一个eval?
发布于 2012-03-25 06:23:34
您可以结合使用is_dir和file_exists来查看该目录是否存在:
if(file_exists($dirname) && is_dir($dirname)) {https://stackoverflow.com/questions/9856138
复制相似问题