我是新来的。我已经搜索了关于上传但仍然没有工作。
这是我的控制器功能
public function tambah() {
$this->data->error = '';
if($_POST){
$this->form_validation->set_rules($this->rules);
$config['upload_path'] = './uploads/berita/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '2048';
$config['max_width'] = '650';
$config['max_height'] = '270';
$config['encrypt_name'] = 'true';
$this->load->library('upload',$config);
if ( ! $this->upload->do_upload())
{
$this->data->error = $this->upload->display_errors();
}
else
{
$data = array('upload_data' => $this->upload->data());
}
}
}
这是我的观点
<?php
if(@$error){echo @$error;}
echo validation_errors();
echo form_fieldset('Penambahan Berita','class="berita"');
echo '<div class="col-left">';
echo form_open_multipart(site_url(uri_string()));
echo form_label('Judul');
echo form_input('judul',@$judul,'class="input-text"');
echo form_label('Berita');
echo form_textarea('berita',@$berita,'style="width:300px;height:100px;"');
echo form_label('Url');
echo form_input('url',@$url,'class="input-text"');
echo form_label('Foto');
echo form_upload('pic');
echo form_submit('submit','Submit','class="input-submit"');
echo form_close();
echo '</div>';
echo form_fieldset_close();
?>
我不知道为什么,但是当我点击提交时有警告:
您没有选择要上传的文件。
答案 0 :(得分:3)
尝试
$this->upload->do_upload('pic')