2015-08-26 29 views
0

我需要將單個圖像文件上載到多個路徑。我嘗試了很多方法。但我失敗了。請幫我解決這個問題。如何使用codeigniter中的多個路徑上載單個文件

我的代碼如下所示:

$config['upload_path'] = './img/post_images/family/'; 
     $config['allowed_types'] = 'gif|jpg|png|jpeg|'; 
     $this->load->library('upload', $config); 
     $this->upload->initialize($config); 
     $field_name ="img_fld"; 
     $rgpic="0"; 
     if (!$this->upload->do_upload($field_name)) 
     { 
     $error = $this->upload->display_errors(); 
     $data['error']=$error; 
     } 
     else 
     { 
     $data = $this->upload->data(); 
     $regpicname=$data['file_name']; 
     $rgpic="1"; 
     } 
     if($rgpic!=0) 
     { 
     $data = array(test_img'=>'img/'.$regpicname, 
         ); 
        } 
     $query = $this->db->insert('images',$data); 

我需要相同的圖像上傳到另一個目錄。請幫幫我 。提前致謝。

+0

使用'copy()'[function](http://php.net/manual/ EN/function.copy.php)。 – Tpojka

回答

0

您可以使用PHP的副本()函數將文件複製到另一個目錄...您當前的上傳路徑是

$config['upload_path'] = './img/post_images/family/'; 

而你所儲存的文件名以$ regpicname

所以做到這一點獲取當前文件路徑

$original_path = $config['upload_path'].$regpicname; 
$new_path = "file path+name+extension"; 

然後使用

copy($original_path, $new_path); 

要複製...請注意,如果文件已經存在於新目錄中,它將被覆蓋...

相關問題