PHP mkdir在if语句中不起作用

时间:2012-04-11 01:27:40

标签: php function codeigniter mkdir

为什么我的mkdir无法在if(is_dir)函数中运行,但它只在单行上方工作?

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

2 个答案:

答案 0 :(得分: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 {

答案 1 :(得分:0)

试试这个:

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