-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
multiple File upload issue #679
Comments
@chistel In the function
to
It will work for now. I would let @lonnieezell check over this though because it is a dead end with |
A couple of thoughts for you @chistel:
|
@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 |
@lonnieezell pls can you give a sample of running a multi file upload to a folder using the |
@lonnieezell Oh skip me, #1 & #2 did that, and 3 I figured that I was on the wrong path. |
@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. <form action="/Shared/Test" method="post" enctype="multipart/form-data">
<input multiple type="file" id="feed-editor-image-input" name="images[]"/>
<input type="submit">
</form> // This doesn't work
print_r( [
$_FILES,
$this->request->getFiles(),
] ); Array
(
[0] => Array
(
[images] => Array
(
[name] => Array
(
[0] => 170586-Subaru_Impreza_WRX-Subaru_Impreza-Subaru-JDM.png
[1] => 17499755_1403719142999697_1454939783_o.jpg
)
[type] => Array
(
[0] =>
[1] => image/jpeg
)
[tmp_name] => Array
(
[0] =>
[1] => D:\Wamp\tmp\php6315.tmp
)
[error] => Array
(
[0] => 1
[1] => 0
)
[size] => Array
(
[0] => 0
[1] => 118352
)
)
)
[1] => CodeIgniter\HTTP\Files\FileCollection Object
(
[files:protected] =>
)
) // This works
print_r( [
$_FILES,
$this->request->getFile( 'images' ),
$this->request->getFiles(),
] ); Array
(
[0] => Array
(
[images] => Array
(
[name] => Array
(
[0] => 170586-Subaru_Impreza_WRX-Subaru_Impreza-Subaru-JDM.png
[1] => 17499755_1403719142999697_1454939783_o.jpg
)
[type] => Array
(
[0] =>
[1] => image/jpeg
)
[tmp_name] => Array
(
[0] =>
[1] => D:\Wamp\tmp\php6141.tmp
)
[error] => Array
(
[0] => 1
[1] => 0
)
[size] => Array
(
[0] => 0
[1] => 118352
)
)
)
[1] =>
[2] => CodeIgniter\HTTP\Files\FileCollection Object
(
[files:protected] => Array
(
[images] => Array
(
[0] => CodeIgniter\HTTP\Files\UploadedFile Object
(
[path:protected] =>
[originalName:protected] => 170586-Subaru_Impreza_WRX-Subaru_Impreza-Subaru-JDM.png
[name:protected] => 170586-Subaru_Impreza_WRX-Subaru_Impreza-Subaru-JDM.png
[originalMimeType:protected] =>
[error:protected] => 1
[hasMoved:protected] =>
[size:protected] => 0
[pathName:SplFileInfo:private] =>
[fileName:SplFileInfo:private] =>
)
[1] => CodeIgniter\HTTP\Files\UploadedFile Object
(
[path:protected] => D:\Wamp\tmp\php6141.tmp
[originalName:protected] => 17499755_1403719142999697_1454939783_o.jpg
[name:protected] => 17499755_1403719142999697_1454939783_o.jpg
[originalMimeType:protected] => image/jpeg
[error:protected] => 0
[hasMoved:protected] =>
[size:protected] => 118352
[pathName:SplFileInfo:private] => D:\Wamp\tmp\php6141.tmp
[fileName:SplFileInfo:private] => php6141.tmp
)
)
)
)
) |
@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 |
@lonnieezell Never mind about my last response and request, I figured it out. I would make a doc regarding it. |
@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. public function getFiles(): FileCollection // <-----
{
if (is_null($this->files))
{
$this->files = new FileCollection();
}
return $this->files; // <-----
} to public function getFiles() // <-----
{
if (is_null($this->files))
{
$this->files = new FileCollection();
}
return $this->files->all(); // <-----
} |
@JakeAi exactly what I did |
@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? |
@JakeAi he is right, I can't find anything broken there.. when I make the doc, I would clarify it |
@chistel Can you post your sample code? |
@JakeAi am on mobile now, but here is what I have,
where the images is the form field name |
@chistel did you add the all() to the IncomingRequest then? Because your code doesn't work out of the box. |
@JakeAi yes I added it |
@chistel Ahhh, that's what I meant about being broken. So something does need changed. |
@JakeAi 🙄🙄🙄 yes just that |
@chistel 's changes have been merged in, so closing this. |
upload of multiple files returns null
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);
The text was updated successfully, but these errors were encountered: