Created
October 20, 2012 19:28
-
-
Save sasezaki/3924483 to your computer and use it in GitHub Desktop.
sandbox for CakePHP style multidimentional field & ZF2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <title>Upload test</title> | |
| </head> | |
| <body> | |
| <h2>Test form for CakePHP style multi dimentional field</h2> | |
| <form name="file-form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"> | |
| <label for="file">Choose Filen:</label> | |
| <br /> | |
| <input type="file" name="data[model][field1]" /> | |
| <br /> | |
| <input type="file" name="data[model][field2]" /> | |
| <br />mode - dump or inputfilter | |
| <input type="text" name="mode" value="dump" /> | |
| <br /> | |
| <input type="submit" nam="submit" id="submit" value="Submit" /> | |
| </form> | |
| </body> | |
| </html> | |
| <?php | |
| require 'tests/_autoload.php'; | |
| $request = new Zend\Http\PhpEnvironment\Request; | |
| if (!$request->isPost()) return; | |
| if ($request->getPost('mode') == 'dump') { | |
| goto dump; | |
| } | |
| inputfilter : | |
| $inputfilter = new Zend\InputFilter\InputFilter; | |
| $inputfilter->add( | |
| ['type' => 'Zend\InputFilter\FileInput', | |
| 'name' => 'data["model"]["field1"]', | |
| 'required' => FALSE, | |
| 'validators' => [ | |
| //['name' => 'fileupload'], | |
| ['name' => 'filesize', 'options' => ['min' => 10, 'max' => 30]] | |
| ] | |
| ] | |
| ); | |
| $inputfilter->setData($request->getFiles()->toArray()); | |
| if (!$inputfilter->isValid()) { | |
| var_dump($inputfilter->getMessages()); | |
| } | |
| $file = $request->getFiles(); | |
| var_dump($file); | |
| return; | |
| dump : | |
| $file = $request->getFiles(); | |
| ?> | |
| $_FILES output <br /> | |
| <?php var_dump($_FILES['data']); ?> | |
| $request->getFiles() output <br /> | |
| <?php var_dump($file['data']); ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $_FILES output | |
| array (size=5) | |
| 'name' => | |
| array (size=1) | |
| 'model' => | |
| array (size=2) | |
| 'field1' => string '' (length=0) | |
| 'field2' => string 'LICENSE' (length=7) | |
| 'type' => | |
| array (size=1) | |
| 'model' => | |
| array (size=2) | |
| 'field1' => string '' (length=0) | |
| 'field2' => string 'application/octet-stream' (length=24) | |
| 'tmp_name' => | |
| array (size=1) | |
| 'model' => | |
| array (size=2) | |
| 'field1' => string '' (length=0) | |
| 'field2' => string '/tmp/phpOcvmzO' (length=14) | |
| 'error' => | |
| array (size=1) | |
| 'model' => | |
| array (size=2) | |
| 'field1' => int 4 | |
| 'field2' => int 0 | |
| 'size' => | |
| array (size=1) | |
| 'model' => | |
| array (size=2) | |
| 'field1' => int 0 | |
| 'field2' => int 1065 | |
| $request->getFiles() output | |
| array (size=1) | |
| 'model' => | |
| array (size=2) | |
| 'field1' => | |
| array (size=5) | |
| 'name' => string '' (length=0) | |
| 'type' => string '' (length=0) | |
| 'tmp_name' => string '' (length=0) | |
| 'error' => int 4 | |
| 'size' => int 0 | |
| 'field2' => | |
| array (size=5) | |
| 'name' => string 'LICENSE' (length=7) | |
| 'type' => string 'application/octet-stream' (length=24) | |
| 'tmp_name' => string '/tmp/phpOcvmzO' (length=14) | |
| 'error' => int 0 | |
| 'size' => int 1065 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment