【发布时间】:2011-01-07 13:05:29
【问题描述】:
这将是模糊的......我已经建立了一个 crud 系统,用于管理数据库中的“报价”,在创建表单和更新表单上都有一个上传字段。
当用户进行编辑时,我会显示图像,但如果他们想上传新图像,则更新表单中的表单字段可以在他们提交更新时上传新图像
棘手的部分是如果他们不想 $this->upload->do_upload() 会转储出一个错误,说没有指定图像
为了解决这个问题,我在 if(!empty($_POST['userfile'])) 上添加了仅在指定图像时才使用上传类,但是当表单提交时,这似乎总是空的,直到它到达上传类函数调用..这里有一些代码
$userfile = $this->input->post('userfile');//i have tried $_POST as well
if( ! empty($userfile))
{
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
echo $this->upload->display_errors();
$data['offer'] = $this->moffers->get_offer($this->input->post('id'));
$this->load->view('admin/admin_header');
$this->load->view('admin/edit',$data);
$this->load->view('admin/admin_footer');
}
关于解决问题的任何想法?当我取出empty()条件时,上传字段工作正常,但如果用户没有指定要上传的文件,他们可能并不总是想要这样做
<tr>
<td>Upload a new image</td>
<td><input type="file" name="userfile" size="40" /></td>
</tr>
【问题讨论】:
标签: php codeigniter