我正在使用以下命令爲每個客戶在Intranet應用程序上創建一個目錄。問題是,如果該目錄已經存在,我得到的錯誤:如果在php中已經存在,則不要創建目錄
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...";
} }
?>
你的意思是MKDIR,我猜。 – Luci 2012-05-02 11:35:59
我做到了。在PHP中使用'_'時完全隨機。 – GolezTrol 2012-05-02 11:37:25