php Codeigniter 文件上传不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15656401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Codeigniter file upload not working
提问by Dinuka Thilanga
I write code for upload a image file. But it always show You did not select a file to upload.
This is my code.
我编写了用于上传图像文件的代码。但它总是显示You did not select a file to upload.
这是我的代码。
view
看法
<?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(); ?>
controller
控制器
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');
}
Please help me.
请帮我。
回答by Svetoslav
At your PHP change
在您的 PHP 更改
$this->upload->do_upload()
to
到
$this->upload->do_upload("add_1")
where "add_1" is your input name attribute.
其中“add_1”是您的输入名称属性。
Codeigniter UPLOAD library docs
P.S. At your HTML the Label attribute for="" is targeting input ID so you have to add id to your input.
PS 在您的 HTML 中, Label 属性 for="" 以输入 ID 为目标,因此您必须将 id 添加到您的输入中。
回答by Jetwiz
i recenly got that problem and solve it. you can check is module fileinfo in php already on? if you can access to CPanel, you can go to SOFTWARE TAB then search Select PHP Version, then you can see list of module and check that module fileinfo. and try to upload again.
我最近遇到了这个问题并解决了它。您可以检查 php 中的模块文件信息是否已经打开?如果您可以访问 CPanel,您可以转到“软件”选项卡,然后搜索“选择 PHP 版本”,然后您可以看到模块列表并检查该模块的文件信息。并尝试再次上传。