php - Uploaded file can not be opened when clicking the link
Get the solution ↓↓↓ {{ trans('cruds.ticket.fields.attachments') }}
<td>
@foreach($ticket->attachments as $attachment)
<a href="{{ $attachment->getUrl() }}">{{ $attachment->file_name }}</a>
@endforeach
</td>
It is displaying error like this when I click on the link...
Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404 localhost Apache/2.4.43 (Win64) OpenSSL/1.1.1g PHP/7.4.5
Answer
Solution:
laravel framework have nice storage mechanism.
And by seeing you code, i assuming that,
the$attachment->getUrl()
should be return something like:localhost/abc.img
and it doesn't match with any resource managed by apache server.
so. let change the link that$attachment->getUrl()
return tolocalhost/files/abc.img
and create a routes for this link like:
Route::get('files/{filename}', function ($filename)
{
$file = Storage::get('files/'.$filename);
$type = $mimetype = Storage::mimeType('product_image/'.$filename);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
});
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: zsh: command not found: php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.