Hello all
--
Erdal YAZICIOGLU
System & Network Engineer
Page Europa S.R.L - General Dynamics
www.pageuropa.it
Office - Rome : +39 0650395292
Mobile -Rome : +39 3490787196
Mobile -Istanbul: +90 536 3447989
I am creating a from where users can upload their images. All images are to be uploaded in uploads directory under public. After creation of the form, in the controller I get the file name with $file = $form->getValues('file'). Up to here everything seems ok.
When I select the picture that I want to upload, as soon as I click the upload button, it uploads the image but also returns a error message.
Here is my picture form
<?php
class Form_Picture extends Zend_Form
{
public function init()
{
$this->setAction('/alumni/change-picture')
->setMethod('post')
->setAttrib('id', 'commentform');
$this->clearDecorators();
$decorators = array(
array('ViewHelper'),
array('Errors'),
array('HtmlTag', array('tag' => 'p')),
array('Label')
,);
$this->addElement('file', 'file',array('label' => 'Lütfen Resim Seçiniz'));
$password = $this->getElement('file')
->addValidator('Extension', false, 'jpg,jpeg,gif,png')
->setAttrib('tabindex','2');
$this->addElement('submit', 'Yükle');
$submit = $this->getElement('Yükle')
->setAttrib('class','button')
->setDecorators(array(array('ViewHelper')));
$this->setDecorators(array('FormElements',array('HtmlTag', array('tag' => 'ul')),
array(array('DivTag' => 'HtmlTag'),
),
'Form'
));
And here is my controller
public function changePictureAction()
{
$form = new Form_Picture();
$this->view->form = $form;
if($this->getRequest()->isPost())
{
$formData = $this->getRequest()->getPost();
if($form->isValid($formData))
{
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->setDestination('uploads');
$upload->receive();
$this->view->fileName = $form->getValue('file');
}
}
}
The interesting this is when I change the position of the $this->view->fileName and put it before $upload->receive(), it gives me the file name but it does not upload.
I can get the filename with getFileName() method but then it returns the name with directory name, like uploads/image.jpg. It needs more code :))
If anybody know a solution please let me know..
Thanks
And the error message is : The file 'file' was illegal uploaded, possible attack
--
Erdal YAZICIOGLU
System & Network Engineer
Page Europa S.R.L - General Dynamics
www.pageuropa.it
Office - Rome : +39 0650395292
Mobile -Rome : +39 3490787196
Mobile -Istanbul: +90 536 3447989
没有评论:
发表评论