0
votes

I'm a just a beginner and I need your help. EDIT : even when I search http://127.0.0.1:8000/storage/uploaded/the_filename I get 404 no found

I've already used php artisan storage:link I get error 404 Not Found when I use <iframe src="/storage/uploaded/{{$data->doc}}">.

Even if I write <iframe src="/storage/uploaded/1628544440.docx"> I still get 404 Not Found. 1628544440.docx is the file name in DB and uploaded folder.

The documents in the folder /storage/app/public/uploaded have the same name of documents->doc in the Database.

What can I change in the code?

In DocumentController:

public function store(Request $request)
{
    $request->validate([
        'doc' =>  'required',...
    ]);

    $document = new document();

    $file = $request->file('doc');
    $filename = time().'.'.$file->getClientOriginalExtension() ;
    $file->storeAs('uploaded', $filename);

    $document->doc = $request->input('doc', $filename);
    $document->candidate_id = $candidate_id; 
    $document->save();
}

public function show($id)
{
    // to select a document that belongs to a candidate
    $doc_id = DB::table('documents')
        ->select('id')
        ->where('candidate_id', $id)
        ->first()
        ->id;
    $data =  document::find($doc_id);

    return view('candidate.document', compact('data'));
}

In candidate/document.blade.php:

<iframe src="/storage/uploaded/{{ $data->doc }}"></iframe>

Thank you in advance.

2
Is storage in the root directory? You might want to try ./storage for the current directory.infinitezero
Show us your file / folder tree. The path to the file is wrong.Grumpy
@infinitezero not it's not in the root directorySarah
/ refers to root ./ refers to current and ../ revers to the parent directory.infinitezero

2 Answers

0
votes

After running the php artisan storage:link, check the <project>/public folder, there should have the corresponding soft-link folder linked to your storage app folder.

Example

ls -la <project>/public
...
lrwxrwxrwx  1 admin   61 Aug  6 12:10 storage -> /home/xxx/storage/app/public/
0
votes

To Save the file:

$file = $request->file('doc');
$filename = time().'.'.$file->getClientOriginalExtension() ;
$document->doc = $filename;
Storage::disk('local')->put($file, $filename);

To access the file

{{asset('storage/'.$data->doc)}}