2014-04-15 11 views
2

나는 다음과 같은 코드가 있습니다메시지 : MKDIR() : 잘못된 인수

$data['user_data'] = $this->session->userdata('user'); 
     $user_id = $data['user_data']["employee_id"]; 

     $f_name = $data['user_data']["f_name"]; 
     $s_name = $data['user_data']["s_name"]; 
     $username = $data['user_data']["user_name"]; 
     $title = $data['user_data']["title"]; 
     $is_active = $data['user_data']["is_active"]; 
     $employee_type = $data['user_data']["employee_type"]; 
     $month = $data['user_data']["month"]; 
     $year = $data['user_data']["year"]; 
    $current_month = date('F'); 

      $current_year = date('Y'); 

      $folder_name = $current_month . $current_year; 
      $directory = "./files/" . $current_month . $current_year; 

      $directory_name = dirname($directory); 

      $last_base_name = basename($directory); 

      $previous_month = $month.$year; 

      $folder_name = $previous_month; 
      echo 'folder name : ......before checking ....'. $folder_name.'</br>'; 


      $filename = "./files/" . $previous_month . "/"; 
      echo 'DIRECTORY: .......'.$filename.'</br>'; 
      echo 'File Name' . $previous_month . '</br>'; 
      if (!file_exists($filename)) { 
       echo 'Directory doesnt exist' . '</br>'; 
        mkdir("./files/".$previous_month."/", 0777); 

       echo "The directory $previous_month was successfully created."; 
       $approved_file_name = "./files/" . $previous_month . "/approved"; 
       if (!file_exists($approved_file_name)) { 
        mkdir("./files/" . $previous_month . "/approved", 0777); 
        echo 'The directory approved was created'; 
       } 
       $un_approved_file_name = "./files/" . $previous_month . "/un_approved"; 
       if (!file_exists($un_approved_file_name)) { 

        mkdir("./files/" . $previous_month . "/un_approved", 0777); 
        echo 'The directory un_approved was created'; 
    } 
나는 내가 sccript을 실행하면 위의 코드 예 March2014 에서 디렉토리를 생성 할

, 나는 다음과 같은 오류가 발생합니다 : 메시지 : mkdir() : 잘못된 인수 그게 옳지 않다고 조언 해주세요. 다음과 같은 유형의 디렉토리 (예 : March)를 만들려고하면 성공합니다.

+0

'$ previous_month = $ month. $ year;'여기서'$ month and $ year' 변수는 어디에 초기화합니까? –

+0

@ShankarDamodaran 상단에서 초기화되는 세션입니다. –

+0

권한 오류와 관련이 있는지 궁금합니다. 특정 디렉토리에 대한 권한을 갖는 스크립트와 같습니다. – Aditya

답변

1

다음과 같은 출력을 실행하면 약간 리팩터링됩니까?

$data['user_data'] = $this->session->userdata('user'); 

$user_id = $data['user_data']["employee_id"]; 
$f_name = $data['user_data']["f_name"]; 
$s_name = $data['user_data']["s_name"]; 
$username = $data['user_data']["user_name"]; 
$title = $data['user_data']["title"]; 
$is_active = $data['user_data']["is_active"]; 
$employee_type = $data['user_data']["employee_type"]; 

//looks for month and year in session, if it doesn't exist set to current 
$month = $data['user_data']["month"] ? $data['user_data']["month"] : date('F'); 
$year = $data['user_data']["year"] ? $data['user_data']["year"] : date('Y'); 

$folder_name = $month . $year; 
//this will add it to files folder under directroy of this file, add /../ etc to navigate to different folder 
$folder_path = dirname(__FILE__) . "/files/" . $folder_name; 

echo "Createing folder structure under [$folder_path] <br />"; 

$folder_path_unapproved = $folder_path . "/unapproved"; 
$folder_path_approved = $folder_path . "/approved"; 

/** 
you could make this following bit a function and call it twice with above strings 
**/ 
if (!file_exists($folder_path_unapproved)) { 
    echo "Directory doesnt exist $folder_path_unapproved <br/>"; 
    //uses the recursive flag to create the parent directory if it doesn't exist 
    $created = mkdir($folder_path_unapproved, 0777, true); 
    if($created) { 
     echo "The directory $folder_path_unapproved was successfully created.";   
    } else { 
     echo "Error createing the directory $folder_path_unapproved.";   
    } 
} 

if (!file_exists($folder_path_approved)) { 
    echo "Directory doesnt exist $folder_path_approved <br/>"; 
    //uses the recursive flag to create the parent directory if it doesn't exist 
    $created = mkdir($folder_path_approved, 0777, true); 
    if($created) { 
     echo "The directory $folder_path_approved was successfully created.";   
    } else { 
     echo "Error createing the directory $folder_path_approved.";   
    } 
}