0

I'm trying to get a path to a file in my storage folder. Although the storage_path() function duplicates the given path.

My code

$firstFile = 'app/public/temp/' . $timestamp . '/' . $tempName . '1.pdf';
$secondFile = 'app/public/temp/' . $timestamp . '/' . $tempName . '2.pdf';
$path1 = storage_path($firstFile);
$path2 = storage_path($secondFile);
dd($path1, $path2);

My result:

"/var/www/html/storage/app/public/temp/public/temp/1678441063/tempName1.pdf/public/temp/1678441063/tempName2.pdf1.pdf"
"/var/www/html/storage/app/public/temp/public/temp/1678441063/tempName1.pdf/public/temp/1678441063/tempName2.pdf2.pdf"

Wanted result:

"/var/www/html/storage/app/public/temp/1678441063/tempName1.pdf"
"/var/www/html/storage/app/public/temp/1678441063/tempName2.pdf"

My filesystem.php (file shortened for only relevant code)

<?php

return [
    'default' => env('FILESYSTEM_DISK', 'local'),

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
            'throw' => false,
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL') . '/storage',
            'visibility' => 'public',
            'throw' => false,
        ],
    ],

    'links' => [
        public_path('storage') => storage_path('app/public'),
    ],

];

I have tried removing app/public from $firstFile but that leaves me with the same result.

I also ran the php artisan storage:link command.

I use php 8.1 and Laravel 9.19

ZodexNL
  • 13
  • 4
  • Try dd ($timestamp, $tempName). I am affraid of that there is something wrong with these variables – Khang Tran Mar 10 '23 at 10:57
  • 1
    @KhangTran Thanks, you were right. I passed the wrong variables instead of the $timestamp and $tempname to the function in which my code is. Such a silly mistake by me. – ZodexNL Mar 10 '23 at 11:10

1 Answers1

0

Fixed thanks to @KhangTran's comment.

My $timestamp and $tempName contained a path instead of what they should contain.

ZodexNL
  • 13
  • 4