我编写了用于上传图像文件的代码。但它总是显示You did not select a file to upload.
,这是我的代码。
<?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"是您的输入名称属性。
Codeigniter上传库文档
注:在你的HTML标签属性for="是针对输入ID,所以你必须添加ID到你的输入。
我最近遇到了那个问题并把它解决了。你可以检查模块fileinfo是否在PHP中打开了?如果你可以访问CPanel,你可以去软件选项卡,然后搜索选择PHP版本,然后你可以看到模块列表,并检查模块文件信息。并尝试再次上传