File not found at path in laravel 7x - laravel

I have an image at storage/public and I want access that with Storage library but i get error "File not found at path"
I search a lot in the internet and I don't get any solution for my problem so please help me.
my code :
$filename = '123.jpg';
$path = storage_path()."/".$filename;
Storage::disk('local')->get($path);
dd($contents);
the error :
Illuminate\Contracts\Filesystem\FileNotFoundException
C:\xampp\htdocs\admin\storage/123.jpg
the things i tried :
php artisan storage:link
the filesystem.php
<?php
return [
'default' => env('FILESYSTEM_DRIVER', 'local'),
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'permissions' => [
'file' => [
'public' => 0664,
'private' => 0600,
],
'dir' => [
'public' => 0775,
'private' => 0700,
],
]
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
],
'links' => [
public_path('storage') => storage_path('app/public'),
],
];

Your file is under storage/public folder but you trying to access it from storage folder.
Check your error path C:\xampp\htdocs\admin\storage/123.jpg
Change
$path = storage_path()."/".$filename;
to
$path = storage_path('public/' . $filename);

Related

Storage issue in web Laravel

I have the issue with storage/uploads/my-folder-name
Everything works perfect in local, but I get broken image icon on the web
I save my links to each image in DB as 'storage/uploads/my-folder-name/file.jpg'
But if I change this path to 'storage/app/public/uploads/my-folder-name/file.jpg' the image is shown correctly
I try to show the image in yajra datatable
I have deleted the storage folder from my public folder and created symbolic link again
So everything should be working but it is not
The filesystem:
'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,
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT',
false),
'throw' => false,
],
],
'links' => [
public_path('storage') => storage_path('app/public'),
],

Storage path is not part of public path Laravel

I wonder what is causing this error when I made a request to a Laravel project using Homestead.
This issue I think is related to storage link.
Storage path /home/vagrant/code/soso-api/storage/app is not part of
public path /home/vagrant/code/soso-api/public
Here's my filesystem.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => public_path('app'),
],
'public' => [
'driver' => 'local',
'root' => public_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
],
in .env FILESYSTEM_DRIVER=public
I already tried
storage unlink
php artisan storage:link
php artisan cache:clear
php artisan config:cache
but to no avail. Let me know if I miss something.
UPDATE:
changed public_path to storage_path doesn't solve the issue.
Change:
'public' => [
'driver' => 'local',
'root' => public_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
To:
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],

How to set path download to my pc after uploaded file

How to set path download to my pc, When i upload pdf file and it's saved at storage\app\public\1\filename.pdf
(1 it's folder generate by queue after successfully upload)
<?php
return [
'default' => env('FILESYSTEM_DRIVER', 'local'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
],
],
'links' => [
public_path('storage') => storage_path('app/public'),
],
];

Reading image from storage_path on a shared host e.g Godaddy, returning error 404

I have a problem reading the url of the file saved to Storage/app/uploads/images/ on goDaddy shared host.
in .env, I configure the APP_URL = www.piggystore.com/server/storage
in a filesystem.php, after running php artisan storage:link
When I upload, the image is stored in Storage/app/uploads/images but to retrieve it is the problem.
I have configured public_path, by changing it in filesystem.php but it is not working as well. What am I getting wrong.
.env file
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
],
];
Saving files in the path
$saveme = storage_path('app/uploads/images/'.$exportName);
$background->save($saveme);
$imag->image = $exportName;
$imag->textwrap = "dev";
$imag->imageOption = $option;
$imag->save();
if (empty($imag)){
return response()->json([
'success' => false,
'message' => 'There was a problem creating the postcard!'
], 201);
}
return response()->json([
'success' => true,
'data' => storage_path('app/uploads/images/'.$exportName),
'message' => 'Postcard created successfully!'
]);
}
All I want is to www.piggystore.com/uploads/images/filename.extension which will display in the browser
Thanks in advance

storing files to aws s3 using laravel

Please give me an example to store files to AWS S3 in laravel 5.5.
I already configured filesystem file with AWS credentials.
I saw the function
Storage::put('file.jpg', $contents);
but don't know what the second parameter is
the contents of filesystem.php file is as follows
return [
'default' => env('FILESYSTEM_DRIVER', 'local'),
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => '*********',
'secret' => '******',
'region' => 'my region',
'bucket' => 'bucketname',
],
],
];
thanks in advance
There is good example in Laravel documentation:
Storage::disk('s3')->put('avatars/1', $fileContents);
The 2nd parameter is is file content so in real life it could look like this:
Storage::disk('s3')->put('file.jpg', file_get_contents('your_local_file.jpg');

Resources