When I was uploading images on my localhost everything worked fine. Now when I uploaded my website to server the image uploads and in DB it shows this: /tmp/phptDVxoK
This is my controller code:
public function themeStore(ThemeRequest $request)
{
$theme = Theme::create($request->all());
$theme->slug = str_slug($theme->title);
if(Input::hasfile('image'))
{
$request->file('image')->move(public_path('images/themes/'), $request->file('image')->getClientOriginalName());
$theme->image = 'images/themes/' . $request->file('image')->getClientOriginalName();
}
Auth::user()->theme()->save($theme);
$theme->category()->attach($request->input('categories_list'));
flash()->success('Dizainas buvo sėkmingai patalpintas į dizainų parduotuvę.');
return redirect('/');
}
Does anybody knows the solution ?
I don't know why you use both Input
and $request
, but I tested in postman, something Input
can get value, but $request
can't and opposite (depend of input type: json, text,..).
If this condition if(Input::hasfile('image'))
return true
, please change syntax:
{
Input::file('image')->move(public_path('images/themes/'), Input::file('image')->getClientOriginalName());
$theme->image = 'images/themes/' . Input::file('image')->getClientOriginalName();
}
Or check hasFile
with $request
: if ($request->hasFile('image')) {}
See more here.