DEV Community

Abolhasan Momeni
Abolhasan Momeni

Posted on

Input type “file” returns EMPTY in Laravel php

We have some photos that need to be updated
The user wants to delete one of the files while editing,
How do you know user has sent a NULL input file or not changes?
becuse Input type “file” returns EMPTY ,
So we have two similar state,
for example:
if($request->hasFile('filename')) {
//here is!!! ok you update the file
//but here not ok,
if you check input exist ,it does not solve the problem

how you handle this!

Discussion (2)

lito profile image
Lito • Edited

Create a checkbox input to mark photo to de deleted:

<input type="checkbox" name="delete" value="1" />
Enter fullscreen mode Exit fullscreen mode

And in the backend service:

if ($request->hasFile('filename')) {
} elseif ($request->input('delete')) {
Enter fullscreen mode Exit fullscreen mode
pudgeline profile image
Abolhasan Momeni Author

good idea,thank's