我已经制作了照片上传功能,无法上传到根目录$this->upload->do_upload('userfile')
中的uploads文件夹,因为它总是进入Material_view页面,因此无效。
查看器:
<?php echo form_open_multipart ('index.php/Main/do_upload'); ?>
<table class="table">
<tr>
<td>Title</td>
<td><?php echo form_input('title'); ?></td>
</tr>
<tr>
<td>Image</td>
<td><?php echo form_upload('userfile'); ?></td>
</tr>
<tr>
<td></td>
<td><?php echo form_submit('submit', 'Save', 'class="btn btn-primary"'); ?></td>
<?php echo form_close(); ?>
</tr>
</table>
控制器
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('Material_view', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
在上传照片后,我可以问一下,如何在观看者中使用它? 非常感谢:)
答案 0 :(得分:0)
我已根据您的新代码更改了我的答案:
您正在调用不正确的字段(因为您没有修改教程的示例以适合您的自定义视图。
控制器:
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('pic'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('Material_view', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}