2016-12-03 7 views
1

コードイグナイタを使用して画像をアップロードしようとしていますが、これは不可能です。理由はわかりません。誰でも助けてくれますか?ここでCodeigniterのファイルアップロード

"I will print $_FILES array "

私は実際に、もちろんこれをテストすることはできないんだけど、私は、これはあなたが始めるだろうと考えてい

public function upload(){ 
$config['upload_path'] = "./assets/uploads/"; 
$config['allowed_types'] = "jpg|png|jpeg|gif"; 
$this->load->library("upload" , $config); 

$rs = $this->upload->do_upload("userfile"); 
print_r($rs); 
print_r($_FILES); 

if(!$rs){ 
$error = array('error'=>$this->upload->display_errors()); 
$this->load->view("main_view", $error); 

} 
else{ 
$file_data = $this->upload->data(); $data['img'] = "localhost/FileUpload/assets/uploads/"; 
$file_data['file_name']; $this->load->view("success_msg" , $data); 
    } 
} 
+0

あなたのファイルアップロードの入力は名前= userfileを持っている必要があります。 – cssBlaster21895

答えて

1

同じようにしてみてください -

public function upload(){ 

     $config['upload_path'] = "./assets/uploads/"; 
     $config['allowed_types'] = "jpg|png|jpeg|gif"; 
     $this->load->library("upload" , $config); 
     $rs = $this->upload->do_upload("userfile"); 
     print_r($rs); 
     echo "<br>" . $rs; 
     if(!$rs){ 
      $error = array('error'=>$this->upload->display_errors()); 
      $this->load->view("main_view", $error); 
     }else{ 
      $file_data = $this->upload->data(); 
      $data['img'] = "http://localhost/FileUpload/assets/uploads/". $file_data['file_name']; 
      $this->load->view("success_msg" , $data); 
     } 

    } 
1

を試してみましたコードです。

public function upload() { 

    $name = 'something'; // set this based on your requirements, I often use random strings or user names according to the situation. 

    $config['upload_path'] = "assets/uploads/"; 
    $config['allowed_types'] = "jpg|png|jpeg|gif"; 
    $config['file_name']  = $name; 

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

    $rs = $this->upload->do_upload("userfile"); 

    print_r($rs); 
    print_r($_FILES); 

    if(!$rs) { 
    $error = array('error'=>$this->upload->display_errors()); 
    $this->load->view("main_view", $error); 
    } 
    else { 
    $file_data = $this->upload->data(); 
    $file_name = $file_data['file_name']; 
    $ext  = pathinfo($file_name, PATHINFO_EXTENSION); //Useful to store your name in database if/when you need to 
    $data  = array('upload_data' => $upload_data); 
    $this->load->view("success_msg" , $data); 
} 

} 
関連する問題