2014-11-25 79 views
0

我想获取上传文件的内容。但是,帖子值正在返回NULL。但$_FILES值正在正确。也试过$this->input->post()但它仍然返回NULL。帖子返回NULL

查看:(upload_contacts.php)

<form enctype='multipart/form-data' method='POST'> 
    <table> 
     <tr> 
      <td> 
      Choose a file to upload: <input name='uploadedfile' type='file' /> 
      </td> 
      <br/> 
     </tr> 
     <tr> 
      <td> 
       <input type='submit' value='submit' /> 
      </td> 
     </tr> 
    </table> 
</form> 

控制器:(contact.php)

public function uploadCSV() 
{ 
    //todo : Crate view 

    $this->config->load('je_settings',TRUE); 
    $tally_folder_path = $this->config->item('folder_path'); 
    if(! empty($_FILES['uploadedfile']['name'])) 
    { 
     var_dump($_FILES['uploadedfile']['name']); 
     var_dump($_POST); 
     die(); 
     $file_type = $_FILES['uploadedfile']['type']; 
     $allowed = array('text/csv','text/comma-separated-values'); 
     if(! empty($_FILES['uploadedfile']['name']) && in_array($file_type, $allowed)) 
     { 
      $tally_src_file = $tally_folder_path . basename($_FILES['uploadedfile']['name']); 
      move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $tally_src_file); 
     } 
     else 
     { 
      die("No file specified or Format not supported"); 
     } 
     $path = "sudo chmod 777 ".$tally_src_file; 
     shell_exec($path); 
     $this->user($tally_src_file); 
    } 
    else 
    { 
     $this->data['om_content'] = $this->load->view('upload_contacts', $this->data, TRUE); 
     $this->data['content'] = $this->load->view('om/_default', $this->data, TRUE); 
     $this->load->view('common/default', $this->data); 
     //$data = array(); 
     //$data['om_content'] = $this->load->view('upload_contacts',$data,TRUE); 

     //$this->load->view("common/default",$this->data); 
    } 

} 

public function user($path) 
{ 
    $fp = fopen($path, "r"); 
    $delimiter = ','; 

    while($row = fgetcsv($fp,1000,$delimiter)) 
    { 
     if($row[0] != 'register_first_name') 
     { 
      $status = 0; 
      $response = ''; 
      $value = array(); 
      $name = ucwords(strtolower($row[0])); 
      $name_array = explode(' ', $name); 
      $value['register_first_name'] = $name_array[0]; 
      unset($name_array[0]); 
      $value['register_last_name'] = 'NLN'; 

      if(isset($name_array)) 
      { 
       $value['register_last_name'] = implode(' ', $name_array); 
       if(empty($value['register_last_name'])) 
       { 
        $value['register_last_name'] = 'NLN'; 
       } 
      } 
      $value['register_phone_number'] = '8888888888'; 
      $value['register_email_address'] = $row[1]; 
      $value['register_username'] = $row[2]; 
      $value['user_group_id'] = $row[3]; 

      $value['register_user'] = 'Submit'; 

      $value['register_password'] = $this->generate_password(); 

      $value['register_confirm_password'] = $value['register_password']; 
      //var_dump($this->input->post('register_user')); 
      $this->register_corp_account($value); 
     } 
    } 
} 
+0

您的'

'缺少属性'行动' – 2014-11-25 07:02:32

+1

减少您的代码 – Vishnu 2014-11-25 07:03:17

+0

您希望在'$ _POST'数组中有什么值?我没有看到除文件字段以外的其他元素? – Cyclonecode 2014-11-25 07:07:41

回答

0

必须设置名称提交输入

<input type='submit' value='submit' name="submit" /> 
+0

为什么我们需要名字? – Torrezzzz 2014-11-25 07:06:23

+0

@Torrezzzz您是否阅读过有关输入标签的文档?你需要名称来定义POST数组。 – 2014-11-25 07:08:51

+0

,因为表单中的所有输入必须有一个要在$ _POST中访问的名称,您有两个输入,第一个类型是文件,并使用$ _FILES ['uploadedfile']访问,另一个输入由$ _POST ['submit '] – h3dgh 2014-11-25 07:10:41

0

也许你缺少form_action="abc.xyz"<form enctype='multipart/form-data' method='POST'>所以它返回NULL值