Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Multiple input file with array in name attribut #115

Open
fdirson-OpenGateway opened this issue Sep 15, 2021 · 0 comments
Open

Multiple input file with array in name attribut #115

fdirson-OpenGateway opened this issue Sep 15, 2021 · 0 comments

Comments

@fdirson-OpenGateway
Copy link

Hello,

If you have this form:

<form method="post" action="#" enctype="multipart/form-data">
    <input type="file" class="form-control" name="photo_name[0]">
    <input type="file" class="form-control" name="photo_name[1]">
</form>

You can't use this component:

$file = new \Upload\File('photo_name', $this->localStorage);

SplFileInfo::__construct() expects parameter 1 to be a valid path, array given

OR

$file = new \Upload\File('photo_name[0]', $this->localStorage);

Cannot find uploaded file identified by key: photo_name[0]

var_dump($_FILES);

array (size=1)
'photo_name' =>
array (size=5)
'name' =>
array (size=1)
0 => string '123.jpeg' (length=43)
'type' =>
array (size=1)
0 => string 'image/jpeg' (length=10)
'tmp_name' =>
array (size=1)
0 => string 'C:\wamp64\tmp\phpDF44.tmp' (length=25)
'error' =>
array (size=1)
0 => int 0
'size' =>
array (size=1)
0 => int 1443745

I don't see anything about this behaviour.

Temporarily i hack \Upload\File constructor like this:

public function __construct($key, \Upload\Storage\Base $storage, ?int $index = null)
    {
        if (! isset($_FILES[$key])) {
            throw new \InvalidArgumentException("Cannot find uploaded file identified by key: $key");
        }
        $this->storage = $storage;
        $this->validations = array();
        $this->errors = array();
        if (is_null($index)) {
            $this->originalName = $_FILES[$key]['name'];
            $this->errorCode = $_FILES[$key]['error'];
            parent::__construct($_FILES[$key]['tmp_name']);
        } else {
            $this->originalName = $_FILES[$key]['name'][$index];
            $this->errorCode = $_FILES[$key]['error'][$index];
            parent::__construct($_FILES[$key]['tmp_name'][$index]);
        }
    }

It seems to work,
i hope you will fix it if you can for next release.

Best regards,

fdirson-OpenGateway added a commit to fdirson-OpenGateway/Upload that referenced this issue May 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant