Jump to content

[SOLVED] ZF: Je suis tres confused!


completeamateur

Recommended Posts

Why is the ZF so baffling?  I'm trying to provide a facility to upload files.  I have created an element within the form...

 

			$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...

 

		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?

Link to post
Share on other sites

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..

Link to post
Share on other sites

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.

Link to post
Share on other sites

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...

 

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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.