2012-04-11 73 views
0

爲什麼我的mkdir不能在if(is_dir)函數中工作,但它僅僅在單線上工作?PHP mkdir不能在if語句中工作

mkdir($location.$folderName, 0777); 

      if(!is_dir($folderName)) 
      { 
       mkdir($location.$folderName, 0777); 

      }else{ 

      //Set File Settings 
       $config['upload_path'] = $location.$folderName; 
       $config['allowed_types'] = 'jpg|png|pdf'; 
       $config['file_name'] = $folderName.'_'.$concept; 
       $config['remove_spaces'] = TRUE; 
       $config['overwrite'] = TRUE; 
       $config['max_size'] = '1024'; 
       $config['max_width'] = '1024'; 
       $config['max_height'] = '768'; 

       $this->load->library('upload', $config); 

       print_r($config); 

       if(!$this->upload->do_upload($conceptOne)) { #= try upload 

       $data['uploadError'] = array('uploadError' => $this->upload->display_errors()); #Error 

       $this->load->view('layout', $data); 

      } // Do upload 
       else{ 
       $data = array('upload_data' => $this->upload->data($conceptOne)); 

       }// end else 
      }// end if folder 
+3

「不工作」意味着你需要更加努力思考。 – 2012-04-11 01:30:31

+0

定義「不工作」。 「if」分支甚至被執行了嗎?你是如何確認它「不工作」的? – deceze 2012-04-11 01:31:16

+1

不知道你通過的是什麼,是腳本執行的同一目錄中的$ folderName?例如。 /scripts/script.php是上面的代碼,但是您正在/ files/<新目錄>中創建一個目錄。可能想要放入絕對路徑並看看會發生什麼。編輯:如果(!is_dir($ location。$文件夾名稱)) – Dave 2012-04-11 01:32:23

回答

1

您的代碼違反其自我......你調用mkdir ($location . $folderName, 0777);但檢查! is_dir ($folderName))這肯定是行不通的

嘗試

$location = "" ; // Your Location 
$foldername = "" ; // Your Folder Name 
$path = $location . DIRECTORY_SEPARATOR . $foldername ; 

if (!is_dir ($path)) { 

    if(is_writable($location)) 
    { 
     mkdir ($path, 0777); 
    } 
    else 
    { 
     die("You don't have permission to create folder"); 
    } 
} 

else { 
0

試試這個:

if (!(file_exists($folderName))) {