teguh_rijanandi's avatar

How to rename file with username/auth.name and file name?

    $file = $request->file('gambar');
    $fileName = $file->getClientOriginalName();
    $request->file('gambar')->move("image/", $fileName);
    $tambah->gambar = Str::slug($request->get('name')). $fileName;
    $tambah->save();

for example i am upload a file with name 1505972507-picsay.jpg (original filename)

and then in image folder changed into teguh-rijanandi1505972507-picsay.jpg? (after upload)

where i must modified the code?

note:

  • this code for show username {{ Auth::user()->name }}
  • I hope will understand
0 likes
3 replies
_Artak_'s avatar

$newName = Auth::user()->name . $fileName;
 // . . .

  $request->file('gambar')->move("image/", $newName);

teguh_rijanandi's avatar

thanks but i am modified again into

$newName = Str::slug($request->get('name')) . $fileName;

teguh_rijanandi's avatar

and then how to filter extension file? i want only jpg and png files are allowed?

Please or to participate in this conversation.