我有多个上传文件的控制器代码,如下所示:
public function submit_add() {
$this->load->library('upload');
$article = new Article_mdl();
$article->artikel_title = $this->input->post('artikel_title');
$article->artikel_date = $this->input->post('artikel_date');
$article->artikel_text = $this->input->post('artikel_text');
$article->arkat_id = $this->input->post('arkat_id');
if (!empty($_FILES['artikel_image']['name'])) {
if (!$this->upload->do_upload('artikel_image')) {
$error = array('error' => $this->upload->display_errors());
print_r($error);
exit();
} else {
$article->user_id = $this->session->userdata('user_id');
$article->artikel_is_active = 1;
$idartikel = $article->insert();
$files = $_FILES;
$cpt = count($_FILES['artikel_image']['name']);
$dataPhoto = array();
for($i=0; $i<$cpt; $i++){
$_FILES['artikel_image']['name']= $files['artikel_image']['name'][$i];
$_FILES['artikel_image']['type']= $files['artikel_image']['type'][$i];
$_FILES['artikel_image']['tmp_name']= $files['artikel_image']['tmp_name'][$i];
$_FILES['artikel_image']['error']= $files['artikel_image']['error'][$i];
$_FILES['artikel_image']['size']= $files['artikel_image']['size'][$i];
$this->upload->initialize($this->set_upload_options());
$this->upload->do_upload();
//echo "<pre>";print_r($xxx);die;
$dataPhoto[] = array('artikel_photo_artikel_id' => $idartikel, 'artikel_photo_images' => $_FILES['artikel_image']['name'], 'artikel_photo_status' => 1);
}
$article->insertArtikelPhoto($dataPhoto);
}
}
redirect('admin/article/');
}
private function set_upload_options(){
// upload an image options
$config = array();
$config['upload_path'] = './upload/article/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['overwrite'] = FALSE;
$config['encrypt_name'] = TRUE;
return $config;
}
我的问题为什么当我提交数据时出现错误“上传路径似乎无效。”文件夹路径配置存在。怎么了? 请帮助...感谢之前的帮助,我将不胜感激:))
答案 0 :(得分:0)
因为服务器没有目录上传
答案 1 :(得分:0)
site_url()
或base_url()
确保您的路径正确无误。777 or rwxrwxrwx
max_size
更改为零以外的其他值。$config['upload_path'] = './upload/article';