I am working on a laravel project which i want to move to production.
Now, created a new folder in the root directory called core and moved all files from the root directory into the 'core' folder.
Now here is my new folder structure
project
|-core
|-every other folders and files
|-public
|-every other asset files
After doing this an updated the path in index.php , the website works well, but the storage images are not loading, it an error that the path was found.
Now, in the public folder, I deleted the storage link and and run php artisan storage:link , I get this return
php artisan storage:link
The system cannot find the path specified.
INFO The [C:\Users\user2\Desktop\project\core\public\storage] link has been connected to [C:\Users\user2\Desktop\project\core\storage\app/public].
But when i go to public, no storage folder link is created.
How can i resolve this?
If you come across this problem, this is how I eventually solved it,
go to config/filesystems.php and replace this
'links' => [
public_path('storage') => storage_path('app/public'),
],
with this;
'links' => [
'../public/storage' => storage_path('app/public'),
],
Related
I have done php artisan storage:link.
So in .vue page the image can't be found by path: :src="'/./storage/'+question.image".
My 404:
The image is uploaded in db:
And stored in storage/app/qImagess:
Structure of public folder:
Could anyone help me, please?
add this to config/filesystems.php in:
'links' => [
...
public_path('qImagess') => storage_path('app/qImagess'),
],
then
php config:clear
php artisan storage:link
the link should be:
127.0.0.1:8000/qImagess/1385873137.png
so add it to vue as:
:src="'/'+question.image"
Here is the Docs for that: https://laravel.com/docs/9.x/filesystem#the-public-disk
Thanks to the help of sir #AhmedAlQahtani, it is done after all.
The problem was in linking:
'links' => [
...
public_path('qImagess') => storage_path('app/qImagess'),
],
This had to be outside of drivers in filesystems.php. That's why php artisan storage:link didn't do the job.
Here is public folder, where created proper qImagess folder is with uploaded images.
I'm trying to backup a gallery folder stored in storage/app/public/gallery so I added
'include' => [
base_path('storage/app/public/gallery'),
],
to the backup config and run 'php artisan backup:run', it gives the error
Backup failed because There are no files to be backed up..
I tried a different approach and change it to
'include' => [
base_path('storage'),
],
The backup works but I get everything inside the storage folder except the public folder. It somehow excludes the public directory.
I have this filesystem config for my folder:
'apks' => [
'driver' => 'local',
'root' => storage_path('app/public/apks'),
'url' => env('APP_URL') . '/storage/apks',
'visibility' => 'public',
]
Here are app apks saved.
I need to return the URL to the file (NOT THE FILE ITSELF).
The android APK manager will then download and install the file by using the URL.
The URL is created by calling:
Storage::disk('apks')->url($result->filename)
It works, the URL looks like this:
https://www.example.com/storage/apks/app-debug.apk
BUT it can not download the file.
Also if I use this URL in the browser I get a 404 error
I would have expected that the file will be downloaded.
You need to generate a symlink for access publicly from the storage folder.
Here you can able to run below command in the composer:
php artisan storage:link
Now you can access:
https://www.example.com/storage/apks/yourfile.xyz
I store files in storage.
No I tried to generate link that open file like:
http://[temp.com]/storage/tests/de139607636857fade861a3c2c472643.txt
But it does not work.
How to open file from storage by URL address?
Files in the storage are not accessible by url by default
You could use Public Disk. For that you need to create symbolic link from public/storage to storage/app/public
From Larvel 5.3 and up, you have artisan command that will help you to create symlink
php artisan storage:link
If you are using older version of Laravel, you can find an answer how to create symbolic link here
Another approach would be to create new disk "uploads", by editing the file config/filesystems.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path(),
],
'uploads' => [
'driver' => 'local',
'root' => public_path() . '/uploads',
],
]
To store files in this location
Storage::disk('uploads')->put($file_name, $file_content);
And to get the file
asset('uploads/'. $file_name)
The storage directory exists outside the web root, as some of the stuff in there shouldn't necessarily be publicly accessible.
https://laravel.com/docs/5.5/filesystem#the-public-disk
The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public. This convention will keep your publicly accessible files in one directory that can be easily shared across deployments when using zero down-time deployment systems like Envoyer.
I strongly recommend not to modify the Laravel's directory structure.
What I would do is to create a URL to download the file, for example:
Route::get('download/{file}', 'DownloadsController#index');
And in that method's controller, put some logic to assert that the file exists and serve it with a response download, for example
public function index($file)
{
$filePath = storage_path('tests/'.$file);
if (! file_exists($filePath)) {
// Some response with error message...
}
return response()->download($filePath);
}
Then you can download your file with a link like this
http://[temp.com]/download/de139607636857fade861a3c2c472643.txt
The controller's way allows you to make some authentication checks before serving the file for example, or to count how many times the file was downloaded.
I have installed a package (ipunkt/laravel-notify) that has assets that need to be published to the public folder. I have tried
php artisan asset:publish ipunkt/laravel-notify
and I get the message
Assets published for package: ipunkt\laravel-notify
however public/packages remains empty.
Any suggestions?
Had to change
'public' => __DIR__.'/../..'
to
'public' => __DIR__.'/../public'
in bootstrap/paths.php