CodeIgniter 文件插入到数据库,但不插入文件夹


public function index(){
$image = null;//tem var
$config['upload_path'] = './assets/uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|jpe|png';
$config['max_size']      = '4000000';
$this->load->library('upload',$config);
$this->form_validation->set_rules('title', 'Album Title', 'required');
if($this->form_validation->run() == FALSE){
$data['imagePath'] = base_url().'assets/uploads/';
$data['album'] = $this->gallery->getAlbum();
$this->load->view('admin/album', $data);
}else{
if (! $this->upload->do_upload('image')){//file upload
$this->image = null;
}else{
$tem = array('upload_data' => $this->upload->data());
$this->image = $tem["upload_data"]["file_name"];
}//end else
$data=array(
'title' => $this->input->post('title'),
'featured' => $this->image,
'created_on' =>  date("Y-m-d")
);
if($this->gallery->createAlbum($data)){
$this->session->set_flashdata('created','Album Has Been Created');
redirect("admin");
}
}   
}
public function viewGallery($album_id){
$config['upload_path']          = FCPATH.'assets/uploads/';
$config['allowed_types']        = 'gif|jpg|jpeg|jpe|png';
$config['max_size']             = 10000;
$this->load->library('upload', $config);
$data['imagePath'] = base_url().'assets/uploads/';
$data['images'] = $this->gallery->getGalleryWithId($album_id);
$data['album_id'] = $album_id;
$this->load->view('addGallery', $data);
}

上载到数据库,但不上载到指定的文件夹... 不知道下一步该怎么做。 任何帮助都会很好。 我不知道在哪里放置应该上传文件的路径文件夹名称。唯一上传到数据库的事情有效。

提前致谢

尝试添加 FCPATH

$config['upload_path'] = FCPATH.'/assets/uploads/';

试试这个。 首先定义要在其中插入文件的任何文件夹名称。 就像在这种情况下,我将"title"作为我末尾的文件夹名称。

if($this->form_validation->run())     
{  
$title=$this->input->post('title');
$config['upload_path']          = './assets/courses/'.$title;
$config['allowed_types']        = 'gif|jpg|png|jpeg';
$config['max_size']             = 1000;
$config['max_width']            = 500;
$config['max_height']           = 300;
$this->load->library('upload', $config);
if (!is_dir('./assets/courses/'.$title)) {
mkdir('./assets/courses/'.$title, 0777, TRUE);
}

希望这会对你有所帮助。

相关内容

  • 没有找到相关文章

最新更新