Did you configure a public link with php artisan storage:link? You have to create a symbolic link to make sure that files are accessible from the web.
Documentation can be found here: https://laravel.com/docs/master/filesystem#the-public-disk
I tried to upload file and download it but when I click my download button there is an error like this,
The file "E:\English HUB\English_HUB\storage\uploads/1633978895_කර්මාන්ත රසායනය.pdf" does not
exist"
this is my controller
public function store(Request $request)
{
$validator = $request->validate([
'file' => 'required|mimes:png,jpg,jpeg,csv,txt,xlx,xls,pdf|max:10000',
'course'=>'required'
]);
$file = new material();
if($request->file()) {
$name = time().'_'.$request->file->getClientOriginalName();
$filePath = $request->file('file')->storeAs('uploads', $name, 'public');
$file->file_name = time().'_'.$request->file->getClientOriginalName();
$genid = (string)Uuid::generate();
$file->uuid = $genid;
$file->file_path = $filePath;
$file->course_id = $request->course;
$file->save();
return back()
->with('success','File has uploaded to the database.')
->with('file', $name);
}
}
download method
public function download($uuid)
{
$file = material::where('uuid',$uuid)->first();
$pathofFile = storage_path($file->file_path);
return response()->download($pathofFile);
}
this is my route
Route::get('/course-material/{uuid}/download',[CourseMaterialsController::class,'download'])->name('file-download');
my upload pdf files save to this path in my project "E:\English HUB\English_HUB\public\storage\uploads"
You are trying to download the file to the client, so the file does not need to be in the public folder. Whether you have the symlink or not is irrelevant in this case.
You have the location where the file is
You have the path that you are trying to give to the download function. THEY MUST BE THE SAME.
Debug the path
public function download($uuid)
{
$file = material::where('uuid',$uuid)->first();
$pathofFile = public_path("storage/'$file->file_path");
dd($pathofFile);
return response()->download($pathofFile);
}
Please or to participate in this conversation.