J'utilise Codeigniter et j'essaie de télécharger plusieurs fichiers dans une base de données. Les fichiers sont des champs séparés pas plusieurs fichiers pour un champ.Codeigniter - téléchargement de fichiers multiples -> insérer dans db - avoir des problèmes!
J'ai suivi ce post - http://codeigniter.com/forums/viewthread/110130/P0/
J'ai presque fonctionner, mais je vais avoir des problèmes avec l'ajout des données téléchargées dans mon db.
Voici ma fonction de contrôleur ...
function addStation(){
// set common properties
$data['title'] = 'Add new station';
$data['action'] = site_url('admin/station/addStation');
$data['link_back'] = anchor('admin/station/index/','Back to list of stations',array('class'=>'back'));
// set validation properties
$this->_set_fields();
$this->_set_rules();
$config['allowed_types'] = 'pdf|xls|doc|docx';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$path_to_uploads='./uploads/files/stations';
$config['upload_path'] = $path_to_uploads;
// File specific (overrule global and optional)
$config['logo_file']['upload_path'] = './uploads/images/stations';
$config['logo_file']['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
//add this
$this->upload->initialize($config);
if (!$this->upload->do_upload(array('rajar_file','playlist_file','map_file', 'logo_file'))){
$error = $this->upload->display_errors();
echo "<script>alert($error);</script>";
}else{
$data = array('upload_data' => $this->upload->data(array('rajar_file','playlist_file','map_file', 'logo_file')));
$rajar_file_name = $upload_data['rajar_file']['file_name'];
$rajar_full_file_path = $path_to_uploads.'/'.$rajar_file_name;
$playlist_file_name = $upload_data['playlist_file']['file_name'];
$playlist_full_file_path = $path_to_uploads.'/'.$playlist_file_name;
$map_file_name = $upload_data['map_file']['file_name'];
$map_full_file_path = $path_to_uploads.'/'.$map_file_name;
$logo_file_name = $upload_data['logo_file']['file_name'];
$logo_full_file_path = $path_to_uploads.'/'.$logo_file_name;
}
// run validation
if ($this->validation->run() == FALSE){
$data['message'] = '';
}else{
// save data
$station = array('name' => $this->input->post('name'),
'rajar' => $rajar_full_file_path,
'playlist' => $playlist_full_file_path,
'map' => $map_full_file_path,
'logo' => $logo_full_file_path );
$id = $this->stationModel->save($station);
// set form input name="id"
$this->validation->id = $id;
// set user message
$data['message'] = '<div class="success">add new station success</div>';
}
$this->template->set('title', 'Admin - Add New Station!');
$this->template->load('admin/template', 'admin/stationEdit', $data);
}
Une fois le formulaire soumis je reçois les erreurs suivantes ...
Message: Undefined variable: rajar_full_file_path
Message: Undefined variable : playlist_full_file_path
Message: Variable indéfinie: map_full_file_path
Message: Variable indéfinie: logo_full_file_path
Suis-je idiot, je n'arrive pas à le comprendre?
Merci Dan