I am working on a Laravel 6 project. Laravel's default folder structure has been modified to look like this:
All of laravel's files are in this folder
/var/www/laravel/releases/2022-01-07/
The storage folder has been moved to
/var/www/laravel/storage
|-- app
|-- logs
|-- public
|-- images
|-- logs
|-- debugbar
|-- framework
|-- logs
A symlink has been created:
ln -nfs "/var/www/laravel/storage" "/var/www/laravel/releases/2022-01-07/storage"
The filesystems.php
file has the disk specified as:
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
I can upload files just fine through my UI, using $request->uploadedImage->store('images', 'public');
. The image file is being place in /var/www/laravel/storage/app/public/images/
. However, after navigating to the view which is supposed to grab the image, the file is not found.
In the blade file, using {{ asset('storage/'.$image) }}
results in https://example.com/storage/images/filename.jpg
, which results in 404; not found.
What are some things I should be checking? At this time, I just feel lost.
I have been fiddling around with different permissions, unfortunately without any success. The laravel/releases/
folder belongs to deployer:deployer
, while the laravel/storage
folder belongs to www-data:www-data
, which doesn't seem to be an issue during upload, so I am not sure if this would be an issue upon retrieving the file? The uploaded image itself belongs to www-data:www-data
.
Thank you very much for taking the time to reading through this issue.
You need to create a link between storage to public as only the later is designed for safe access. Try to execute php artisan storage:link In your Laravel project folder.
More details, please refer https://laravel.com/docs/6.x/filesystem#the-public-disk
I've had a problem like that. Unfortunately, I couldn't solve it and I tried everything. The solution I used was to retrieve the files via download since I was not able to display files in a view.
In routes:
Route::get('download/{id}', 'App\Http\Controllers\CandidateController@filedownload')->middleware(['auth'])->name('file.download');
In controller:
public function filedownload($id)
{
try {
$candidate = Candidate::find($id);
} catch (Exception $e) {
return abort(403, $e);
}
return Storage::download($cadidate->document_file);
}
In view:
<tr style="text-align:center; vertical-align: middle;">
<td>
<a class="link" href="{{ route('file.download', [$candidate->id]) }}">Download</a>
</td>
</tr>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.