2014-02-14 24 views
0
<?php 
$dirPath = "Admin/new_images"; 
$result = mkdir($dirPath, 0777); 
if ($result == 1) { 
echo $dirPath . " has been created"; 
} else { 
    echo $dirPath . " has NOT been created"; 
} 
?> 

此代碼與我的本地主機正常工作。 但它沒有在現場服務器上工作。 任何人都可以幫助我嗎?如何使用PHP在Live Server中創建目錄?

+0

得到'__DIR__'轉儲來檢查你是否在正確的道路或沒有? –

+1

你在窗口上工作嗎? – codemania

+0

是的,我們正在使用windows – user3309162

回答

0

試試這個:

<?php 
$dirPath = "Admin/new_images"; 
$result = mkdir($dirPath, 0777, true); 
chmod($dirPath, 0777); 

if ($result == 1) { 
echo $dirPath . " has been created"; 
} else { 
    echo $dirPath . " has NOT been created"; 
} 
?> 

窗u必須改變$dirPath象下面這樣:

$dirPath = "Admin\\new_images"; 
+0

不工作不運氣.. – user3309162

0

mkdir - 新建目錄

說明

bool mkdir (string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]]) 

在試圖創建由路徑名指定的目錄。

參數:

路徑的目錄路徑。

模式默認情況下,模式爲0777,這意味着可能的最寬訪問權限爲 。有關模式的更多信息,請閱讀chmod() 頁面上的詳細信息。

注意:

模式在Windows上被忽略。

請注意,您可能希望將模式指定爲八進制數 這意味着它應該有一個前導零。該模式也由當前的umask修改爲 ,您可以使用umask()更改該模式。

遞歸允許創建在 路徑名中指定的嵌套目錄。默認爲FALSE。

上下文注意:上下文支持與PHP 5.0.0一起添加。有關context的 說明,請參閱流函數

返回值

成功返回TRUE或FALSE的失敗。

<?php 

/** 
* Makes directory, returns TRUE if exists or made 
* 
* @param string $pathname The directory path. 
* @return boolean returns TRUE if exists or made or FALSE on failure. 
*/ 

function mkdir_recursive($pathname, $mode) 
{ 
    is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); 
    return is_dir($pathname) || @mkdir($pathname, $mode); 
} 

?> 
0

試試下面的代碼

<?php 
test(); 
function test(){ 
    $root_path = $_SERVER['DOCUMENT_ROOT']; 
    $directory_name = 'testDir'; 
    if (!file_exists($root_path.'/'.$directory_name)) { 
     if(mkdir($root_path.'/'.$directory_name, 0777, true)){ 
      print "Directory created successfully."; 
     }else{ 
      print "Error in creating Directory."; 
     } 
    }else{ 
     print "Directory already exists."; 
    } 
} 
?>