Shedman's avatar

File Path Error

I am trying to attach a pdf to an email. I am passing the details with the path to the file.

$details = [
					'message' => 'Here is a new signed pdf',
					'attachment' => $storage_path.'/app/public/'.$document_id.'.pdf'
				];

Then I am attaching it to the build function

public function build()
    {

        return $this->subject($this->details['title'])->view('contracts.mail')->attachFromStorage($this->details['attachment']);
    }

I get an error that the path is wrong.

[previous exception] [object] (League\Flysystem\FileNotFoundException(code: 0): File not found at path: home/forge/domain.com/storage/app/public/39861cca-5676-4c51-8478-bdb4de9a31bf.pdf at /home/forge/domain.com/vendor/league/flysystem/src/Filesystem.php:389)

If I SSH into the site I can see this document in views.

cd domain.com/storage/framework/views/
0 likes
2 replies
jlrdw's avatar

Consider storing somewhere out of web altogether

private static final String UPLOAD_DIRECTORY = "/stohere/uploads";  where ever

Not laravel just example.

Then

'attachment' => UPLOAD_DIRECTORY . '/' . $document_id.'.pdf'

Also if you

echo $storage_path.'/app/public/'.$document_id.'.pdf';
die;

Is that correct, if not that's the problem.

Shedman's avatar
Shedman
OP
Best Answer
Level 2

I failed to create a symbolic link by using

php artisan storage:link

Then accessing it this way.

asset('storage/file.txt');

Please or to participate in this conversation.