2017-07-25 18 views
0

私はファイルをアップロードするために次のコードを使用しています。続きCodeigniter:モバイル経由でアップロードするファイル

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

      $files = $_FILES; 

      $cpt = count($_FILES['userfile']['name']); 
      $this->data['data']= $files; 

      $this->upload->initialize($this->set_upload_options()); 
      for($i=0; $i<$cpt; $i++) { 

       $_FILES['userfile']['name']= $files['userfile']['name'][$i]; 
       $_FILES['userfile']['type']= $files['userfile']['type'][$i]; 
       $_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i]; 
       $_FILES['userfile']['error']= $files['userfile']['error'][$i]; 
       $_FILES['userfile']['size']= $files['userfile']['size'][$i];  


       $this->data['name']= $_FILES['userfile']['name']; 
       $this->data['type']= $_FILES['userfile']['type']; 

       if($this->upload->do_upload()){ 
        $this->db->insert('attachment', array(
         'type'  => 'quotation', 
         'typeid' => $lastid, 
         'path'  => $_FILES['userfile']['name'], 
         'extension' => $_FILES['userfile']['type'], 
        )); 
        $this->data['message'] = 'File Uplaoded'; 

       } 
       else { 
        $this->data['message'] = $this->upload->display_errors(); 

       } 
      } 
      echo json_encode($this->data); die; 


private function set_upload_options() 
    { 
     //upload an image options 
     $config = array(); 
     $config['upload_path'] = './uploads/'; 
     $config['allowed_types'] = 'gif|jpg|png|mp4|jpeg'; 
     $config['max_size']  = '*'; 
     $config['overwrite']  = FALSE; 


     return $config; 
    } 

は、私たちがこれは、モバイル開発者は応じて取得するものです

data =  { 
     userfile =   { 
      error = 0; 
      name = imgname; 
      size = 146245; 
      "tmp_name" = "/tmp/phppYlH8A"; 
      type = "image/jpeg"; 
     }; 
    }; 
    message = "<p>You did not select a file to upload.</p>"; 
    name = s; 
    type = i; 

で取得出力されます。

私は、ファイルのために、以下のしようとした場合

<form action="formlink" method="post" accept-charset="utf-8" enctype="multipart/form-data"> 
<input type="file" name="userfile[]" /> 
<input type="file" name="userfile[]" /> 

<br /><br /> 

<input type="submit" value="upload" /> 

</form> 

をアップロードしますどのように我々はこの

+0

変更 ' $ config ['max_size'] = '*'; '' $ config ['max_size'] = ''; ' – Shihas

答えて

0

を修正することができますが、データをアップロードするためのコードの下に使用する必要が私を助けてください:

$config = array(
      'upload_path' => $path, 
      'allowed_types' => 'jpg|gif|png|jpeg', 
      'overwrite' => 1, 
      ); 
      $this->load->library('upload', $config); 
      $images = array(); 
      foreach ($files['name'] as $key => $image) { 
       if ($image != '') { 
        $_FILES['userfile[]']['name'] = $files['name'][$key]; 
        $_FILES['userfile[]']['type'] = $files['type'][$key]; 
        $_FILES['userfile[]']['tmp_name'] = $files['tmp_name'][$key]; 
        $_FILES['userfile[]']['error'] = $files['error'][$key]; 
        $_FILES['userfile[]']['size'] = $files['size'][$key]; 
        $image = str_replace(' ', '_', $image); 
        $fileName = time() . '_' . $image; 
        $images[] = $fileName; 
        $config['file_name'] = $fileName; 
        $this->upload->initialize($config); 
        if ($this->upload->do_upload('images[]')) { 
         $this->upload->data(); 
        } else { 
         return false; 
        } 
       } 
      } 
関連する問題