Php 上载带有2个独立输入字段的文件
有一个表单,用户输入全名、年龄、个人资料图片、文档并提交。我设法让表单使用一个文件上传,但我找不到一个合适的方法从两个不同的输入上传文件 下面是我的表格 HTMLPhp 上载带有2个独立输入字段的文件,php,codeigniter,file-upload,Php,Codeigniter,File Upload,有一个表单,用户输入全名、年龄、个人资料图片、文档并提交。我设法让表单使用一个文件上传,但我找不到一个合适的方法从两个不同的输入上传文件 下面是我的表格 HTML <form enctype="multipart/form-data" action="" method="post"> <div class="form-group"> <label>Name</label>
<form enctype="multipart/form-data" action="" method="post">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="full_name"/>
</div>
<div class="form-group">
<label>Age</label>
<input type="text" class="form-control" name="age"/>
</div>
<div class="form-group">
<label>Choose Profile pic</label>
<input type="file" class="form-control" name="userfile1"/>
</div>
<div class="form-group">
<label>Choose Document</label>
<input type="file" class="form-control" name="userfile2"/>
</div>
<div class="form-group">
<input class="form-control" type="submit" name="upload" value="UPLOAD"/>
</div>
</form>
名称
年龄
选择个人资料图片
选择文档
PHP
if ($this->input->post('upload'))
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|doc|docx|pdf';
$config['max_size'] = 10000;
$config['max_width'] = 3000;
$config['max_height'] = 3000;
$this->load->library('upload', $config);
if ( !$this->upload->do_upload('userfile1'))
{
$this->session->set_flashdata('status','<div class="alert alert-danger alert-style-square">
<p style="text-align:center">There was an error. Try again. '.$this->upload->display_errors().'</p>
</div>');
}
else
{
$data = array('upload_data' => $this->upload->data());
$values = array('full_name'=>$this->input->post('full_name'),
'age'=>$this->input->post('age'),
'profile_image'=>$this->upload->data('file_name'),
//'document'=>$this->upload->data('file_name'),
'uploaded_date'=>date("Y-m-d H:i:s"));
var_dump($values);
}
}
if($this->input->post('upload'))
{
$config['upload_path']='./uploads/';
$config['allowed_types']='gif | jpg | png | doc | docx | pdf';
$config['max_size']=10000;
$config['max_width']=3000;
$config['max_height']=3000;
$this->load->library('upload',$config);
如果(!$this->upload->do_upload('userfile1'))
{
$this->session->set_flashdata('状态','
出现错误。请重试。“$this->upload->display_errors()。”
');
}
其他的
{
$data=array('upload_data'=>$this->upload->data());
$values=array('full\u name'=>$this->input->post('full\u name'),
'age'=>this->input->post('age'),
'profile\u image'=>this->upload->data('file\u name'),
//'document'=>this->upload->data('file_name'),
“上传日期”=>日期(“Y-m-d H:i:s”);
var_dump(价值);
}
}
非常感谢您的帮助和指导您可以尝试更改
if ( !$this->upload->do_upload('userfile1'))
到
这样做需要用户上传两个图像。如果只需要一个图像,您可以尝试将和更改为或,您可以尝试更改
if ( !$this->upload->do_upload('userfile1'))
到
这样做需要用户上传两个图像。如果只需要一个图像,您可以尝试将和更改为或,谢谢。。。但是我如何分别获得文件名呢?似乎您应该使用
'profile\u image'=>$this->upload->data('userfile1'),
和'document'=>$this->upload->data('userfile2'),
谢谢。。。但是如何分别获取文件名呢?似乎您应该使用'profile\u image'=>$this->upload->data('userfile1'),
和'document'=>$this->upload->data('userfile2'),