Filename? Or file input name? Do you not own the form that is submitting files to your application?
Nov 16, 2022
5
Level 1
hasFile
Can I somehow use a filename I don't know? It can be image_1 image_2 and so on.
This does not work:
$request->hasFile('image_*');
Level 104
@deekepMaks in that case, you can get all of the uploaded files using $request->allFiles() - but this is a little blunt because you don't know the original input name.
You could instead have named the file inputs as an array; e.g.
<input type="file" name="images[]">
<input type="file" name="images[]">
<input type="file" name="images[]">
Now you know the key images - and the items in the array will be accessed using $request->files('images') regardless the number.
If needed (whenever adding or removing), you can include the index for each input (similar to your current solution, e.g.
<input type="file" name="images[2]">
Please or to participate in this conversation.