I wanted to ask what is it like to upload to a host and save it? Of course in the storage folder
Why does this source of mine upload in localhost but not in Host?
But it does not upload at all in the host.
public function store(Request $request)
{
$path = $request->file('image') ?? null;
if ($request->hasFile('image'))
{
$file = $request->file('image');
$name = time();
$extension = $file->getClientOriginalExtension();
$fileName = $name . '.' . $extension;
$path = $file->storeAs('images/aboutExhibitions', $fileName, 'public');
}
AboutExhibition::query()->create([
'user_id' => auth()->id(),
'title' => $request->title,
'link' => $request->link,
'image' => $path,
'options' => $request->options,
'body' => $request->body,
]);
return redirect()->route('admin.aboutExhibitions.index');
}
In the meantime, when I was inside the localhost, I executed the following command before.
php artisan storage:link
CodePudding user response:
Hope this will work.
$image = $request->image;
$image_name=uniqid().date('dmYhis');
$ext=strtolower($image->getClientOriginalExtension());
$image_full_name=$image_name.'.'.$ext;
$image_url=$upload_path.$image_full_name;
$success=$image->move($upload_path,$image_full_name);
$data = array();
$data['image']=$image_url;
$store = Custom::create($data);