2013-03-19 56 views
1

我想爲我的網站上的每個用戶創建一個上傳文件夾,並在特定區域顯示他們的照片。我已經能夠讓codeigniter上傳助手工作,並可以上傳文件到一個文件夾。現在,我希望能夠:如何使用戶上傳文件夾並在codeigniter中顯示特定內容?

  1. 已經由特定用戶上傳的照片被放在一個文件夾中有關特定動態創建自己的ID

  2. 自動調整大小的照片了兩個用戶大小。縮略圖和大尺寸

我想我有它如何做這些事情的研究建立我只是不知道如何將他們的ID的語法以及創建一個文件夾,上傳。

最後一步將顯示這些照片在我選擇的位置綁定到他們的ID。

這裏是我的控制器

public function upload() 
    { 
     mkdir('./upload/' . $this->session->userdata('id'), 0777); 
     $config['image_library'] = 'gd2'; 
     $config['source_image'] = 'PATH TO FOLDER??'; 
     $config['create_thumb'] = TRUE; 
     $config['maintain_ratio'] = TRUE; 
     $config['width']  = 75; 
     $config['height'] = 50; 

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

     $this->image_lib->resize(); 
     $config['upload_path'] = './uploads/'; 
     $config['allowed_types'] = 'gif|jpg|png'; 
     $config['max_size'] = '100'; 
     $config['max_width'] = '1024'; 
     $config['max_height'] = '768'; 

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

     if (! $this->upload->do_upload()) 
     { 
      $error = array('error' => $this->upload->display_errors()); 

      $data['main_content'] = 'account/upload'; 
      $this->load->view('includes/templates/main_page_template', $data); 
     } 
     else 
     { 
      $data = array('upload_data' => $this->upload->data()); 

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

回答

1

您正在創建的用戶目錄,但沒有將其設置爲上傳路徑...

$user_folder = './upload/' . $this->session->userdata('id'); 
if(!is_dir($user_folder)){ 
    mkdir($user_folder, 0777); 
} 
... 
$config['upload_path'] = $user_folder; 
.... 
+0

,完美的工作。謝謝! – LightningWrist 2013-03-19 20:22:52

+0

這是工作,但我仍然收到錯誤:「嚴重性警告:mkdir()[functon.mkdir]:文件存在 – LightningWrist 2013-03-25 17:13:06

+0

檢查目錄是否存在,然後再嘗試創建它..我會更新答案。 – stormdrain 2013-03-25 17:22:54

相關問題