Jump to content

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 comment
https://forums.phpfreaks.com/topic/134997-solved-zf-je-suis-tres-confused/
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..

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.

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.

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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