Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Uploading multiple files doesn't work anymore (in conjunction with the Validator) #15658

Closed
dhardtke opened this issue Sep 29, 2016 · 3 comments

Comments

@dhardtke
Copy link

dhardtke commented Sep 29, 2016

  • Laravel Version: 5.3.11
  • PHP Version: 7.0 (stable)
  • Database Driver & Version: MariaDB (latest stable)

Description:

PR #15166 broke my file upload. I dug into the code and found out that is_uploaded_file() in isValid() returns false when being invoked from within the Validator with the changed code from the PR.

Steps To Reproduce:

This is a part of my code:

public function upload(Request $request) {
    $files = $request->files->get("files");
    foreach ($files as $i => $file) {
        $validator = $this->getValidationFactory()->make($files, [
            $i => "mimes:jpeg,jpg,png|max:3072"
        ], $custom_messages, []);

        if ($validator->fails()) {
        /*
            var_dump($file->isValid());
            die();
        */ // funny: isValid() returns true at this point
            var_dump($validator->failed());die();
            }
    }
}

Output:

array(1) {
  [0]=>
  array(1) {
    ["Mimes"]=>
    array(3) {
      [0]=>
      string(4) "jpeg"
      [1]=>
      string(3) "jpg"
      [2]=>
      string(3) "png"
    }
  }

So I can see the mime rules are failing.

If I var_dump() the guessed extension of the $file by calling var_dump($file->guessClientExtension()); die(); I correctly get jpeg.

I also tried calling $validator->setFiles([...]); but that didn't help either.

@themsaid
Copy link
Member

I don't seem to understand your issue, using your code on a fresh laravel 5.3 installation works for me, uploading 3 valid files passes, uploading any invalid files fails with the correct message.

It's not clear what your issue is, is it because the guessed extension is not correct at your end?

@themsaid
Copy link
Member

ping @dhardtke

@dhardtke
Copy link
Author

Okay, I'm closing this since I've got it working by validating all files before uploading them in my foreach loop. I still don't understand why, when I upload two files, the validation of the second file results in an "uploaded" error ("uploaded" rule failing). I guess it must have two do with the upload of the two interfering each other somehow.

Somehow, is_uploaded_file() returns false for the second file in the loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants