probléme avec upload image
Salut,
je suis entraine mnt de faire ulpoad une image et insérée URL dans ma BD
voici le code de mon formulaire :
Code:
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
|
<?php
class FormulaireUpload extends Zend_Form
{
public function __construct($uploadPath,$options = null)
{
parent::__construct($options);
$this->setName('upload');
$this->setMethod('post');
$this->setAttrib('enctype', 'multipart/form-data');
$id=new Zend_Form_Element_Hidden('id');
$host=new Zend_Form_Element_Hidden('host');
$upfile = new Zend_Form_Element_File('upfile');
$upfile->setLabel('upload picture : ')
->setRequired(true)
->addValidator('NotEmpty')
->addValidator('Extension',false,array('jpg','png','gif','bmp'))
->addValidator('size',false,1048576)
->setDestination($uploadPath);
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Upload');
$this->addElements(array($id, $host,$upfile, $submit));
}
} |
controller.php
Code:
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 35 36 37 38 39 40 41 42 43 44
|
public function pictureAction()
{
$id = (int)$this->_request->getParam('id',0);
$ctr=new Country_CountryDes();
$country=$ctr->fetchRow('CTR_ID='.$id);
$lien="/var/www/test/htdocs/images/country/".$country->NAME;
$upv="/htdocs/images/country/".$country->NAME;
$up=realpath($lien);
$this->view->upv=$upv;//le lien à envoyer vers la vue
//affichage des images de cet pays
$im=new Picture_Picture();
$imgs=$im->fetchAll('PICTURE_ID='.$id);
$this->view->imgs=$imgs;
//le nom du fichier
$tab=explode(" ",$country->NAME);
$nom=implode("_",$tab);
$nom.="_".$country->NOMBRE_IMAGES;
$form = new FormulaireUpload();
$form->getElement('host')->setValue($id);
$this->view->form = $form;
//tester si le formulaire est posté
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
$name=$form->getValue('upfile');
$tab=explode('.',$name);
$newtab=array();
$newtab[0]=$nom;
$newtab[1]=$tab[sizeof($tab)-1];
$newname=implode(".",$newtab);
rename($up."\\".$name, $up."\\".$newname);
if ($form->isValid($formData)) {
$img=new Picture();
$row=$this->createRow();
$row->PICTURE_ID=$form->getValue('host');
$row->URL=$newname;
$row->save();
$this->_redirect('/country/picture/id/'.$id);
} else
$form->populate($formData);
}
} |
et voici l'erreur qui je trouve :
Code:
1 2 3 4
|
Notice: Undefined index: filters in /var/www/test/application/lib/Zend/File/Transfer/Adapter/Abstract.php on line 796
Fatal error: Unsupported operand types in /var/www/test/application/lib/Zend/File/Transfer/Adapter/Abstract.php on line 796 |
j'ai fait qlq recherche et j'ai trouve que on ne peut pas utilise addElement dans file :
Code:
1 2
|
"do not use addElement an the file element the reason is that getValue() will be called the file elements but they have no value and behave false in such a condition" |
SVP si qlq peut me donner un coup de main (des rémarques, suggestion....)
Et merci d'avance