Image does not go in database with file name only tmp name saved?

- 1 answer

Ad

i am new in laravel 5.1 when i upload image they goes to in folder but in database actual name don't saved. The database have name like: C:\wamp\tmp\phpCA22.tmp.

Ad

Answer

Ad

As the OP is not revealing the code.

I am giving the general workarouod

Step 1 : If you get input file

if(Input::file())
{
//Your stuff here
}

Step 2 : Get the File's name

$image = Input::file('image');
$filename = $image->getClientOriginalExtension();

Note :

  1. Don't forget to have multipart/form-data in your form

  2. Have the name of your image as image

Update :

Here's the update code that you'd require

public function uploadImage(Request $request) 
{
 if($request->hasFile('image'))
 { 
 $destinationPath=public_path().'/images/';
 $file = $request->file('image');
 $filename=$file->getClientOriginalName();
 $request->file('image')->move($destinationPath,$filename);
 } 
 $inputs['filename'] =  $request->file('image'); 
 #$inputs['yourkey'] = 'yourdata';
 $users = Upload::create($inputs); 
 return redirect('user/upload'); 
 }

$inputs is the array. You should have the filename in the fillables in your model also make sure filename exists in your table

Update 2 : As the OP gives the coloumn name

public function uploadImage(Request $request) 
{
 if($request->hasFile('image'))
 { 
 $destinationPath=public_path().'/images/';
 $file = $request->file('image');
 $filename=$file->getClientOriginalName();
 $request->file('image')->move($destinationPath,$filename);
 } 
 $inputs['image'] =  $request->file('image'); 
 $users = Upload::create($inputs); 
 return redirect('user/upload'); 
 }
Ad
source: stackoverflow.com
Ad