這是控制器,和我有沒有錯誤在codeigniter中上傳不起作用。可能是什麼原因?
public function admin_page(){
if($this->input->post('add_product')){
if(empty($_FILES['userfile']['name'])){
$data = array(
'category' => $this->input->post('category') ,
'product_name' => $this->input->post('name') ,
'description' => $this->input->post('description'),
'image' => 'no_image.jpg'
);
} else{
$config['upload_path'] = './public/images/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|JPG';
$config['max_size'] = '1000';
$this->load->library('upload', $config);
$this->upload->do_upload('userfile');
echo 'uploaded :)';
$data = array(
'category' => $this->input->post('category') ,
'product_name' => $this->input->post('name') ,
'description' => $this->input->post('description'),
'image' => $_FILES['userfile']['name']
);
}
$this->load->model('products');
$this->products->add_product($data);
}
$this->load->view('admin_page');
}
查看
<form action="<?php echo base_url();?>admin/admin_page" method="post" enctype="multipart/form-data">
<div class="col-xs-3">
<div class="form-group">
<label for="exampleInputEmail1"> Product name </label>
<input type="text" name="name" class="form-control" >
</div>
<div class="form-group">
<label for="exampleInputEmail1"> Category </label>
<input type="text" name="category" class="form-control">
</div>
<div class="form-group">
<label for="exampleInputEmail1"> Description </label>
<textarea class="form-control" name="description" rows="3"></textarea>
</div>
<div class="form-group">
<label for="exampleInputEmail1"> Image </label>
<input type="file" name="userfile" class="form-control">
</div>
<input type="submit" name="add_product" class="btn btn-default" value="OK" />
</div>
</form>
</div>
您有錯誤報告嗎? – Linus
不,沒有錯誤,上傳不起作用... – Ani
請添加您的視圖。通過點擊編輯按鈕來回答你的問題。 – user4419336