Valid Stream Upload File




I try to use Zend Expressive, but I don’t understand how use FileRenameUpload and I can’t valid my form.

if ($request->getMethod() === 'POST') {
            $this->imageForm->setData(array_merge($request->getParsedBody(), $request->getUploadedFiles()));
            if ($this->imageForm->isValid()) {

I put this in my form class to move file after upload :

public function getInputFilterSpecification()
        return [
                'name'     => 'file',
                'required' => true,
                'filters'  => [
                        'name' => 'FileRenameUpload',
                        'options' => [
                            'target' => __DIR__.'../../../data/upload',
                            'useUploadName' => true,
                            'useUploadExtension' => true,
                            'overwrite' => true,
                            'randomize' => true

But when I do isValid on form, just this error :

"fileUploadFileErrorNoFile" => "File was not uploaded"

I don’t understand how use a Stream and valid it

I do right ? I readed doc but nothing about upload and valid form for Expressive.



The various file validators and input types do not currently work with PSR-7, which is what Expressive uses. You will have to handle those separately currently.

We’re working on a new validation/input filter component (spec), and will likely tackle file upload validation, filtering, etc. in that component.


For now, you can use Psr7Bridge like this:

use Zend\Psr7Bridge\Psr7ServerRequest;

$zendRequest        = Psr7ServerRequest::toZend($request);


Funny enough, I was just going to write a similar question. Saved some time now though I did not find a ready-to-use solution.



thanks you for your fast replies. (and for your blog samsonasik :smiley: )

I didn’t read anything about non-fonctinal validators and inputfilters.

I took Psr7Bridge and it works like a charm.

There is a cleaner how to way to do this ?

You’re welcome Ralf.