本文介绍了Codeigniter文件上传不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写用于上传图片文件的代码。但它总是显示您没有选择要上传的文件。
这是我的代码。
I write code for upload a image file. But it always show You did not select a file to upload.
This is my code.
查看
<?php echo form_open_multipart('template/advertisement', array('id' => 'template-add-form', 'class' => 'form-horizontal')); ?>
<?php echo form_fieldset('Add Advertisement', array('class' => '')); ?>
<div class="control-group">
<label class="control-label" for="add_l">Left Advertisement </label>
<div class="controls">
<input type="file" name="add_l"/>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="submit" name="add" value="Update Advertisement" class="btn btn-primary" />
</div>
</div>
<?php echo form_fieldset_close(); ?>
<?php echo form_close(); ?>
控制器
public function advertisement()
{
$headerData = array();
$headerData['title'] = ucfirst('Advertisement');
$data = array();
if ($this->input->post() !== FALSE) {
$config = array();
$config['upload_path'] = './images/add';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['max_filename'] = '100';
$this->load->library('upload', $config);
if ($this->upload->do_upload()) {
$data['message'] = $this->upload->data();
} else {
$data['error'] = $this->upload->display_errors('<div class="alert alert-error">', '</div>');
}
}
$this->load->view('template/header.php', $headerData);
$this->load->view('template/advertisement.php', $data);
$this->load->view('template/footer.php');
}
请帮助我。
推荐答案
您的PHP更改
$this->upload->do_upload()
到
$this->upload->do_upload("add_1")
其中add_1是您的输入名称属性。
where "add_1" is your input name attribute.
PS在HTML中,=的Label属性定位输入ID,因此您必须在输入中添加ID。
P.S. At your HTML the Label attribute for="" is targeting input ID so you have to add id to your input.
这篇关于Codeigniter文件上传不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!