Laravel uploaded file name change is not working
So I'm uploading an image and I want to change the name of it to:
logo_{{Auth::user()->firstName}}_{{Auth::user()->lastName}}
and I want to keep the extension. In my controller I have :
<?php namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;
class UploadController extends Controller {
public function upload(){
if(Input::hasFile('file')){
echo 'Uploaded';
$file = Input::file('file');
$file->move('uploads ', $file->getClientOriginalName());
$custom_name = 'logo_{{Auth::user()->firstName}}_{{Auth::user()->lastName}}'.$file->getClientOriginalExtension();
echo '<img src="uploads/' . $file->getClientOriginalName() . '"/>';
}
}
}
So yes actually it's getClientOriginalName so ofc it will keep the same name, but how can I change it like this?
@saly3301
I think you have syntax issues.
Use this-
$custom_name = "logo_".Auth::user()->firstName."_".Auth::user()->lastName.$file->getClientOriginalExtension();
$file->move(public_path('uploads'), $custom_name); // destination path, name of file
Please or to participate in this conversation.