Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Master Zend Framework:
Create a Simple File Upload Form in Zend Framework 2
Jun 04, 2014 @ 16:51:06

On his "Master Zend Framework" site today Matthew Setter has a new tutorial showing you how to create a simple file upload through the forms handling in Zend Framework 2. The form will include three parts: an input filter, a form class and a controller action to request to show the resulting form.

Having trouble getting file uploads integrated into your forms in Zend Framework 2? Or are you just curious about how to do it, and you want a quick rundown? If either of these is you, come walk through today’s post with me as I show you a simple example of how it’s done – along with how to combine it with filters and validators. Before we get started, I could have composed the code in a much shorter form than have I’ve composed it. But my assumption is that you’re likely using the full-stack framework.

He includes summaries describing each of the three parts of the setup and the code you'll need to create each. The validator checks for things like "too big", "too small" and the correct MIME type on the file given. The form itself only includes the file upload element with a description of "Attachment". The controller action creates the form instance and calls an "isValid" when the upload happens to execute the validation. He also throws in the view template to display the form itself.

tagged: zendframework2 simple file upload tutorial form

Link: http://www.masterzendframework.com/forms-2/simple-file-upload-form


Trending Topics: