M
M
matros972019-03-28 09:44:06
Laravel
matros97, 2019-03-28 09:44:06

Original name when uploading a file?

This is how I upload the file to the server,

if($request->hasFile('img')) {
    $file = $request->file('img')->store('uploads', 'public');
}

everything works, but the file name is
jLyiDxpJWkhiImPOBVwNo6yd3HQciCKTAPLIWsAv.jpeg
Tell me how to return the normal file name,

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Popov, 2019-03-28
@be_a_dancer

This is a valid file name that excludes duplicates within the same directory so that the contents of the file are not overwritten. If you wish, you can read the laravel documentation, which tells how to work with the methods of this class.
If you still want to save the file with the original name, there is also a solution below. You can pass a second parameter to the storeAs method with the file name.

$path = $request->file('avatar')->storeAs(
    'avatars', $request->user()->id
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question