1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| function add($id = null){
if(!empty($this->data)){
$this->Article->id = $id;
$extension = pathinfo($this->data['Article']['nom_fichier']['name'], PATHINFO_EXTENSION);
if(!empty($this->data['Article']['nom_fichier']['tmp_name'])&& in_array($extension, array('csv')) ){
$fichier = $this->data['Article']['nom_fichier']['tmp_name'];
$handle = fopen($fichier, "r");
while($tab=fgetcsv($handle,4096,';')){
$numero=utf8_encode($tab[0]);
$donnees = array(
'Article' => array('nom_article'=> $this->data['Article']['nom_article']),
'Piece' => array(array('numero'=>$this->data['Piece']['numero'],
'article_id'=>$this->data['Article']['id']))
);
debug($donnees);
//$this->Article->Piece->create();
//$this->Article->Piece->saveAll($donnees);
}
//$this->Session->setFlash('Votre liste a été ajoutée.','sucess');
//$this->redirect(array('action'=>'index', $this->Article->id));
}else if (!empty($this->data['Article']['nom_fichier']['tmp_name'])){
$this->Session->setFlash('Vous ne pouvez pas envoyer ce type de fichier');
}
}
} |
Partager