Post返回NULL

时间:2014-11-25 06:59:49

标签: php codeigniter

我正在尝试获取上传文件的内容。但是post值返回NULL。但是$_FILES值正在变得正确。还试过$this->input->post()但它仍然返回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);
         }
     }
}

2 个答案:

答案 0 :(得分:0)

您必须为提交输入设置名称

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

答案 1 :(得分:0)

也许您在form_action="abc.xyz"中遗漏了<form enctype='multipart/form-data' method='POST'>,因此它返回NULL值