2013-04-30 79 views
1

我一直在嘗試使用代碼點火器上傳圖像,並且當上傳文件夾剛好位於應用程序文件夾之外時,它完美地工作。但我的問題是,當我嘗試訪問整個代碼點火器文件夾之外的文件夾時,它會向我發送錯誤消息。如何訪問代碼點火器文件夾外的文件夾?我試過$ _SERVER ['DOCUMENT_ROOT']。但它有助於。訪問文件夾外部代碼點火器

$name = $_POST['name']; 
     $id = $_POST['id']; 
     if (isset($_FILES['upload']['name'])) { 
      // total files // 
      $count = count($_FILES['upload']['name']); 
      // all uploads // 
      $uploads = $_FILES['upload']; 

      for ($i = 0; $i < $count; $i++) { 
       if ($uploads['error'][$i] == 0) { 
        $firstimage = $uploads['name'][$i]; 
        $secondimage = $uploads['name'][$i]; 

        move_uploaded_file($uploads['tmp_name'][$i], $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/'.$uploads['name'][$i]); 
        $config2['image_library'] = 'gd2'; 
        $config2['source_image'] = $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/'.$uploads['name'][$i]; 
        $config2['new_image'] = $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/thumbnail/'.$uploads['name'][$i]; 
        $config2['maintain_ratio'] = FALSE; 
        $config2['create_thumb'] = TRUE; 
        $config2['thumb_marker'] = '_thumb'; 
        $config2['width'] = 75; 
        $config2['height'] = 50; 
        $config2['overwrite'] = TRUE; 

        $this->image_lib->initialize($config2); 
        $this->load->library('image_lib',$config2); 
        if (! $this->image_lib->resize()) 
        { 
         echo $this->image_lib->display_errors(); 
        } 

        $config3['image_library'] = 'gd2'; 
        $config3['source_image'] = $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/'.$uploads['name'][$i]; 
        $config3['new_image'] = $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/resize/'.$uploads['name'][$i]; 
        $config3['maintain_ratio'] = FALSE; 
        $config3['create_thumb'] = TRUE; 
        $config3['thumb_marker'] = '_thumb'; 
        $config3['width'] = 470; 
        $config3['height'] = 470; 
        $config3['overwrite'] = TRUE; 

        $this->image_lib->initialize($config3); 
        $this->load->library('image_lib',$config3); 
        if (! $this->image_lib->resize()) 
        { 
         echo $this->image_lib->display_errors(); 
        } 

        } 


      } 
      $this->load->view('head'); 
      $data = array(
       'name' => $name, 
       'id' => $id 
      ); 
+0

這非常含糊。我們需要您使用的代碼示例來訪問外部文件夾以及使其成爲外部文件夾的目錄結構示例。 – Samutz 2013-04-30 14:15:14

+0

感謝您更新信息。 tuition文件夾實際上是在document_root文件夾中還是在它之外? – Samutz 2013-04-30 14:23:12

+0

文檔根。路徑是這樣的。 www/tuition/tuitionimage/idvalue/ – 2013-04-30 14:24:19

回答

1

在評論中討論後,該問題可能是()函數試圖將文件移動到不存在的目錄move_uploaded_file。

move_uploaded_file($uploads['tmp_name'][$i], $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/'.$uploads['name'][$i]); 

在可以移動文件之前,需要創建文件夾。如果$ id是新的,它可能還沒有創建。所以...

if (!is_dir($_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id)) { 
    mkdir($_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id); 
} 
move_uploaded_file($uploads['tmp_name'][$i], $_SERVER['DOCUMENT_ROOT'].'tuition/tuitionimage/'.$id.'/'.$uploads['name'][$i]); 
+0

實際上已經存在一個帶有tat名稱的文件夾。它不是那個問題 – 2013-04-30 15:02:51

+0

我不知道還有什麼要告訴你。錯誤說該文件夾不存在。我在我的一個CI應用程序上嘗試了相同的代碼,並且它工作正常。 – Samutz 2013-04-30 15:29:04