bogdy's avatar
Level 10

Image Upload with original name in Laravel 5.6

Hi, I want to upload a image and save image name in database. but i get in databse the "/tmp/phpDtIEgI" that is a .tmp file instead of image name. in laravel storage is upload the right file with original name but in database only .tmp file


Users::create($request->only('name', 'vorname', 'linkde', 'linken', 'logo'));
        $image = Input::file('logo');
        $filename = $image->getClientOriginalName();
        $destinationPath = 'bilder/logo';

        // store the file
        $image->storeAs("$destinationPath", $filename);

        return redirect('users')->with('succes', "Uhuu");


//thanks in advance
0 likes
8 replies
Dhaval_patel's avatar

@bogdy print this out in your method Input::file('logo')->getClientOriginalName(); this should return entire file name

bestmomo's avatar

When you say "in database" do you mean in users table ? Because you dont use getClientOriginalName on it...

newbie360's avatar
Level 24

because you proccess the image after the create, none of code is to save the new image path

one is get the image path first then create

$image = Input::file('logo');
$filename = $image->getClientOriginalName();
$destinationPath = 'bilder/logo';

// store the file
$image->storeAs("$destinationPath", $filename);

// now here you know the image path and name

// change this line the value of 'logo'
Users::create($request->only('name', 'vorname', 'linkde', 'linken', 'logo'));
return redirect('users')->with('succes', "Uhuu");

or add one more step override your logo after you created

$user = Users::create($request->only('name', 'vorname', 'linkde', 'linken', 'logo'));
        $image = Input::file('logo');
        $filename = $image->getClientOriginalName();
        $destinationPath = 'bilder/logo';

        // store the file
        $imagePath = $image->storeAs("$destinationPath", $filename);

        // override the logo
        $user->timestamps = false;
        $user->logo = $imagePath;
        $user->save();
        
        
        return redirect('users')->with('succes', "Uhuu");
1 like

Please or to participate in this conversation.