Answer the question
In order to leave comments, you need to log in
How to upload images to Laravel server?
if ($request['files']){
$files = $request->file('files');
foreach ($files as $file) {
$path = $file->store('uploads/company');
$disk->setVisibility($path, 'local');
$created_photo = CompanyFile::query()->create([
'company_id' => $id,
'file_type' => $path,
]);
}
}
Answer the question
In order to leave comments, you need to log in
Try instead $path = $file->store('uploads/company'); use move
$filename = $this->getFileName($request->file);
$request->image->move(base_path('uploads/company'), $filename);
Function code that I use in my projects.
It implies loading using AJAX, then this does not change the essence of the matter
public function uploadGallery(Request $req) {
try {
$files = $req->file('photo');
foreach ($files as $file) {
$tmp1 = md5(microtime());
$tmp2 = md5(uniqid());
$newName = strtolower(substr(base64_encode($tmp1 . $tmp2), 0, 7)).'.'.$file->getClientOriginalExtension();
//здесь важная поправка куда перемещать - это абсолютный путь
//так что к слову media в моём случае нужно ещё применить функцию base_path или конкотинировать результат функции public_path
$file->move('media', $newName);
//Storage::putFileAs('/public/ //строчка закомментирована, но можно использовать её
}
} catch (\Exception $err) {
//$errorcode = $err->getMessage();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question