我完成了这项工作并使用了我以前的项目。现在,我正在做一个新项目,并试图将我的代码复制并粘贴到文件上传中..它没有价值..我的问题是为什么我的文件上传没有得到价值?
注意:我已经在帮助器中声明了表单,并且文件夹已经存在。我的列名称是img_jumbotron,我的CI版本是3.3(最新)
查看
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Upload New Image</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="titleLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header modal-header-success">
<button type="button" class="close btn btn-primary" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="titleLabel">New Image</h4>
</div>
<div class="modal-body">
<div class="container">
<div class="panel-body">
<div class="text-content">
<div class="col-md-2 col-lg-5">
<br>
<form method="post" enctype="multipart/form-data" action="<?= base_url().'Administrator/addContent/'?>">
dklfjkdf
<input type ="text" name ="example">
<div class="form-group">
<label>Image</label>
<input type="file" required class="form-control" name="userfile"/>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<span class="pull-right">
<button type="submit" class="btn btn-success">Upload File</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</span>
</form>
</div>
</div>
</div>
</div>
控制器
public function addContent()
{
$config['upload_path'] = './uploaded/';
$config['max_size'] = '2048000';
$config['overwrite'] = TRUE;
$config['allowed_types'] = '*';
$this->load->library('upload', $config);
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="alert alert-danger" role="alert">', '</div>');
$example = $_POST['example'];
$example = $this->input->post('userfile');
print_r($example);die;
if ($this->form_validation->run() == FALSE || !$this->upload->do_upload('userfile'))
{
echo ('ksldfhsdj');
}
else
{
$content = array(
'img_jumbotron' => $this->input->post('userfile'),
'upload_data' => $this->upload->data()
);
print_r($content);die;
$this->AdminModel->addContent($content);
redirect('Administrator/headContent');
}
模型
public function addContent($content)
{
$content = array(
'img_jumbotron' => $this->input->post('userfile'),
'img_jumbotron' => $this->upload->data('file_name')
);
$this->db->insert('content', $content);
}
答案 0 :(得分:0)
您可以在浏览器上使用开发人员工具并检查NETWORK(我猜是否为chrome)选项卡,并检查您的应用程序是否正在发送文件。
还有:
action="<?=base_url().'Administrator/addContent/'?>"
我认为您应该删除此“<?=
”上的等号。