Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After you have validated the form in your controller you can use <code>$form-&gt;getData();</code></p> <p>there should be a key 'file' as that is what you named your file element. Within that a key 'tmp_name'.</p> <p>This will be the randomized name.</p> <p>Eg: </p> <pre class="lang-php prettyprint-override"><code>public function uploadfileAction() { //get form and filter $form = $this-&gt;getServiceLocator()-&gt;get('SomeModule\Form\UploadFileForm'); $filter = $this-&gt;getServiceLocator()-&gt;get('SomeModule\Form\UploadFileFilter'); $form-&gt;setInputFilter($filter-&gt;getInputFilter()); if ($this-&gt;getRequest()-&gt;isPost()) { //merge files with post $post = array_merge_recursive( $this-&gt;getRequest()-&gt;getPost()-&gt;toArray(), $this-&gt;getRequest()-&gt;getFiles()-&gt;toArray() ); //set data in form $form-&gt;setData($post); //check is valid- form data will now contain new name if ($form-&gt;isValid()) { var_dump($form-&gt;getData()); } } } </code></pre> <p>The resulting array dump may look something like this:</p> <pre class="lang-php prettyprint-override"><code>array(13) { ["file"]=&gt; array(5) { ["name"]=&gt; string(14) "some-pdf.pdf" ["type"]=&gt; string(24) "application/pdf" ["tmp_name"]=&gt; string(46) "/public/tmpuploads/new-randomized-name.pdf" ["error"]=&gt; int(0) ["size"]=&gt; int(651264) } ["submit"]=&gt; string(6) "Submit" ["csrf"]=&gt; string(32) "4df771bb2fb14e28992a408583745946" } </code></pre> <p>You can then just do:</p> <pre class="lang-php prettyprint-override"><code>$formData = $form-&gt;getData(); $fileNewLocation = $formData['file']['tmp_name']; //do what you want with $fileNewLocation </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload