I use below script to uploade a file to the sevre. it works fine on the local host (wamp server), but when I try to use it on the server I figure out that the uploaded file size is 0 byte.
Any one know taht where is the problem?
public function uploadFile(Request $request)
{
$request->validate([
'name' => 'required',
'auther_id'=>'required',
'doc_type'=>'required',
'file'=>'required|mimes:pdf'
]);
$fileModel = new File;
$fileName = time().'_'.$request->file->getClientOriginalName();
$filePath = $request->file('file')->storeAs('uploads', $fileName, 'public');
$fileModel->name = time().'_'.$request->file->getClientOriginalName();
$fileModel->file_path = '/storage/' . $filePath;
$fileModel->save();
}
2
Answers
Reason of this error was permissions of some folders. I just reset the host completely and now everything work like a charm.
I think you can use like this. first of all you need to store your file inside storage. then you can get public url from storage.
Try this way