Image does not go in database with file name only tmp name saved?
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 :
Don't forget to have
multipart/form-data
in your formHave 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
Related Questions
Ad
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → How do i get base url in OctoberCMS?
- → Image does not go in database with file name only tmp name saved?
- → ListView.DataSource looping data for React Native
- → how to retrieve image from database in laravel 5.1?
- → Carousel in Laravel 4 does not show as expected
- → angular ng-repeat and images in a row
- → Keeping uploaded files secure but still available via https
- → Upload file with iron-ajax (Google Polymer)
- → How can I get Greasemonkey to highlight visited image links?
- → File upload does not work Laravel
- → Populating array with items from different HTML attributes
- → Replacing background image javascript
Ad