You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
below is what i tried <input accept="image/*" multiple type="file" id="feed-editor-image-input" name="images[]"/> $imagesFile = $this->request->getFiles('images'); var_dump($imagesFile);
Is your form setup with enctype=multipart/form-data? Forgetting that is a common error, for me anyway.
Did you dump the $_FILES variable to ensure there was anything actually uploaded that the server recognized?
You're calling getFiles('images), however that method simply returns all files within a FileCollection class (and, yes, @JakeAi that's the way it should be. The FileCollection class provides some handy helper functions you might want to use.). To retrieve a single file, you should use the getFile() method (singular). Or use getFiles() and then you can do checks like hasFile(), etc.
Finally, when trying to access a single file of an array of files like you have here, you should use dot array syntax.
@JakeAi That was my first solution, but it returned error say Hercules must be an instance of FileCollection except I have to remove the instance from it
@chistel I might be able to pull something together tonight (just getting my morning started here), but you never answered the questions - especially #1 and #2.
@lonnieezell Oh skip me, #1 & #2 did that, and 3 I figured that I was on the wrong path.
Now it's returns all. but it would be better using specific field name than just returning all uploaded file. Especially if I have two different file field in a single form
@lonnieezell I couldn't even get getFiles to work without modifications. getFiles creates a new FileCollection class, but there is no construct and doesn't call any functions?, and this->files is null. If you call getFile('w/e') and then getFiles, it works.
@JakeAi I figured it out in to ways, either add the all method of FileCollection into a constructor or go with the previous method you suggested but removing the fileCollection instance from getFiles() method
@chistel Oh, right on. I'm still confused though. Is @lonnieezell right? Or is something broken? Like, I understand about the helper functions, but I couldn't get it to work at all. populateFiles doesn't get called at all through getFiles(). Are you supposed to $files=getFiles() then $files->getFile()? I feel like it's an inconvenience. I'd like to get files and then foreach the files and call the helpers on those iterations?
Activity
JakeAi commentedon Aug 16, 2017
@chistel In the function
getFiles()on line 487 of the IncomingRequest class, if you changeto
It will work for now. I would let @lonnieezell check over this though because it is a dead end with
getFiles().lonnieezell commentedon Aug 16, 2017
A couple of thoughts for you @chistel:
enctype=multipart/form-data? Forgetting that is a common error, for me anyway.getFiles('images), however that method simply returns all files within a FileCollection class (and, yes, @JakeAi that's the way it should be. The FileCollection class provides some handy helper functions you might want to use.). To retrieve a single file, you should use thegetFile()method (singular). Or usegetFiles()and then you can do checks likehasFile(), etc.Iamscalla commentedon Aug 16, 2017
@JakeAi That was my first solution, but it returned error say Hercules must be an instance of FileCollection except I have to remove the instance from it
Iamscalla commentedon Aug 16, 2017
@lonnieezell pls can you give a sample of running a multi file upload to a folder using the
getFiles()methodlonnieezell commentedon Aug 16, 2017
@chistel I might be able to pull something together tonight (just getting my morning started here), but you never answered the questions - especially #1 and #2.
Iamscalla commentedon Aug 16, 2017
@lonnieezell Oh skip me, #1 & #2 did that, and 3 I figured that I was on the wrong path.
Now it's returns all. but it would be better using specific field name than just returning all uploaded file. Especially if I have two different file field in a single form
JakeAi commentedon Aug 16, 2017
@lonnieezell I couldn't even get getFiles to work without modifications. getFiles creates a new FileCollection class, but there is no construct and doesn't call any functions?, and this->files is null. If you call getFile('w/e') and then getFiles, it works.
Iamscalla commentedon Aug 16, 2017
@JakeAi I figured it out in to ways, either add the all method of FileCollection into a constructor or go with the previous method you suggested but removing the fileCollection instance from
getFiles()methodIamscalla commentedon Aug 16, 2017
@lonnieezell Never mind about my last response and request, I figured it out. I would make a doc regarding it.
JakeAi commentedon Aug 16, 2017
@chistel All you need to do is return all() and remove the return type after getFiles(). You don't need to necessarily remove the instance.
to
Iamscalla commentedon Aug 16, 2017
@JakeAi exactly what I did
JakeAi commentedon Aug 16, 2017
@chistel Oh, right on. I'm still confused though. Is @lonnieezell right? Or is something broken? Like, I understand about the helper functions, but I couldn't get it to work at all. populateFiles doesn't get called at all through getFiles(). Are you supposed to $files=getFiles() then $files->getFile()? I feel like it's an inconvenience. I'd like to get files and then foreach the files and call the helpers on those iterations?
Iamscalla commentedon Aug 16, 2017
@JakeAi he is right, I can't find anything broken there.. when I make the doc, I would clarify it
JakeAi commentedon Aug 16, 2017
@chistel Can you post your sample code?
Iamscalla commentedon Aug 16, 2017
@JakeAi am on mobile now, but here is what I have,
where the images is the form field name
<input type="file" name="images[]" multiple />JakeAi commentedon Aug 16, 2017
@chistel did you add the all() to the IncomingRequest then? Because your code doesn't work out of the box.
Iamscalla commentedon Aug 16, 2017
@JakeAi yes I added it
JakeAi commentedon Aug 16, 2017
@chistel Ahhh, that's what I meant about being broken. So something does need changed.
Iamscalla commentedon Aug 16, 2017
@JakeAi 🙄🙄🙄 yes just that
lonnieezell commentedon Aug 17, 2017
@chistel 's changes have been merged in, so closing this.