Author Topic: [SOLVED] ZF: Je suis tres confused!  (Read 1652 times)

0 Members and 1 Guest are viewing this topic.

Offline completeamateurTopic starter

  • Enthusiast
  • Posts: 69
    • View Profile
[SOLVED] ZF: Je suis tres confused!
« on: December 01, 2008, 10:34:19 AM »
Why is the ZF so baffling?  I'm trying to provide a facility to upload files.  I have created an element within the form...

Code: [Select]
$image = new Zend_Form_Element_File('image');
$image->setLabel('Photo')
->setAttrib('enctype', 'multipart/form-data')
->setRequired(false)
->setDestination('/upload/catalogue/images')
->addValidator('Count', false, 1) // ensure only 1 file
->addValidator('Size', false, 1024000) // limit to 1MB
->addValidator('Extension', false, 'jpg,png,gif'); // only JPEG, PNG, and GIFs

...and the controller consists of...

Code: [Select]
if ($this->_request->isPost()) {

$formData = $this->_request->getPost();

Zend_Debug::dump($_FILES);
exit;

...but this just returns...

array(0) {
}

i.e. no file is uploaded!  I don't understand what I'm doing wrong.  Any suggestions?

Offline completeamateurTopic starter

  • Enthusiast
  • Posts: 69
    • View Profile
Re: ZF: Je suis tres confused!
« Reply #1 on: December 01, 2008, 02:26:10 PM »
I've just upgraded from ZF 1.5 -> ZF 1.7 and it now throws a form validation error...

    * The file '' could not be found
    * The file '' was not found

Offline awpti

  • Enthusiast
  • Posts: 453
  • Gender: Male
    • View Profile
    • GoMySQL - DBA Blog and Tutorials
Re: ZF: Je suis tres confused!
« Reply #2 on: December 01, 2008, 06:46:14 PM »
I can only tell you that ZF makes my eyes melt and brain explode. On a very random basis.

I can't even determine from your code why it would throw the errors your seeing, let alone why it was previously kicking back an empty array. That's weird.

It LOOKS fine..
Server: Apache 2.2.3 - PHP 5.2.17, MySQL 5.0, 5.1, 5.5 and 6.0 - 2x Quad Core Xeon 5620 w/ 16G Mem
GeekLAN - Ignited Jobs - LAMP Tips

10+ Years of hobby PHP Development and Database Design.

Offline Daniel0

  • Administrator
  • 'Insane!'
  • *
  • Posts: 11,815
  • Gender: Male
  • ^bb|[^b]{2}$
    • View Profile
Re: ZF: Je suis tres confused!
« Reply #3 on: December 02, 2008, 07:13:40 AM »
Try something like this:

if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
	
if (!
$form->picture->receive()) {
	
	
throw new 
Zend_Exception('The picture could not be uploaded.'); 
	
}
	
else {
	
	
Zend_Debug::dump($form->getValues());
	
}
}


Also, setAttrib('enctype', 'multipart/form-data') should be done on the form, not the element.

Offline completeamateurTopic starter

  • Enthusiast
  • Posts: 69
    • View Profile
Re: ZF: Je suis tres confused!
« Reply #4 on: December 02, 2008, 09:31:29 AM »
Daniel,

I've made the modifications you have suggested and it looks as if we're half way there.

I seem to have some permissions problems as it is throwing the following errors...

Quote
Warning: move_uploaded_file(/Library/WebServer/Documents/bbusl/public/upload/catalogue/images/European Cup.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /Library/WebServer/Documents/library/Zend/File/Transfer/Adapter/Http.php on line 102

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/private/var/tmp/phpdDRdh9' to '/Library/WebServer/Documents/bbusl/public/upload/catalogue/images/European Cup.jpg' in /Library/WebServer/Documents/library/Zend/File/Transfer/Adapter/Http.php on line 102

Warning: move_uploaded_file(/Library/WebServer/Documents/bbusl/public/upload/catalogue/images/European Cup.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /Library/WebServer/Documents/library/Zend/File/Transfer/Adapter/Http.php on line 102

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/private/var/tmp/phpdDRdh9' to '/Library/WebServer/Documents/bbusl/public/upload/catalogue/images/European Cup.jpg' in /Library/WebServer/Documents/library/Zend/File/Transfer/Adapter/Http.php on line 102

I'm running Mac OS X, PHP 5.2.5, Apache 2.0.  Any suggestions?

Thanks in advance.

Offline Daniel0

  • Administrator
  • 'Insane!'
  • *
  • Posts: 11,815
  • Gender: Male
  • ^bb|[^b]{2}$
    • View Profile
Re: ZF: Je suis tres confused!
« Reply #5 on: December 02, 2008, 09:39:40 AM »
Yeah it sounds like permission problems. Try to chmod the upload dir recursively to allow write permissions for the httpd.

Offline completeamateurTopic starter

  • Enthusiast
  • Posts: 69
    • View Profile
Re: ZF: Je suis tres confused!
« Reply #6 on: December 02, 2008, 09:59:34 AM »
Yup, all sorted... no doubt that will throw another couple of hundred questions within the next 5 mins!! ;-)

Out of interest, what's the default chmod (i.e. not 777)?

Regards.

P.S. Any suggestions re the complex query I posted??
« Last Edit: December 02, 2008, 10:00:30 AM by completeamateur »

Offline Daniel0

  • Administrator
  • 'Insane!'
  • *
  • Posts: 11,815
  • Gender: Male
  • ^bb|[^b]{2}$
    • View Profile
Re: ZF: Je suis tres confused!
« Reply #7 on: December 02, 2008, 10:09:49 AM »
Out of interest, what's the default chmod (i.e. not 777)?

The default chmod depends on the umask. On my VPS the umask is 022, meaning that "write" (=2) will not be set for "group" and "other". This essentially means the default is 644 for files and 755 for dirs because the full access mode is 666 and 777 for files and dirs, respectively. If you care, then it's full & ~umask that'll be the default.