I have set Laravel dropzone and it's working on my project.
I have cloned that project and trying to modify things but when I'm trying to upload files it's working and they are in the storage but when I want to see my files that I have uploaded I get
404
Sorry, the page you are looking for could not be found. error
This is my link when I click on the document
I'm using Laragon
EDIT:
I noticed that I have public >storage>storage
path:
public\storage\storage
And also a file named storage where I have a public file with an app file where inside I have another storage file
something like
path:
storage\app\public\storage\
Your link is looks like incorrect, http://mylocal.test/storage/storage/eOSuhkeabtKGuj4PRGePv0dxl8Fl0iQ3n7qLKvHs.pdf the storage path repeated on the url.
Can you try single storage path in the url?
http://mylocal.test/storage/eOSuhkeabtKGuj4PRGePv0dxl8Fl0iQ3n7qLKvHs.pdf
SOLUTION: when you clone your project delete public>storage and run
php artisan storage:link
to link it with your new path
Related
I am deploying my first project on a shared hosting.
I followed this tutorial to deploy the website and turn the public folder into the public_html folder of my hosting plan.
When I upload an image from my website (with storeAs() method), the file is uploaded in the private/storage folder, not the public one (where I would like).
The asset() function try to display the image from public_html/storage.
What can I do ?
Thank you :)
My files are like this :
private/
- app/
- bootstrap/
- config/
- database/
- resources/
- routes/
- storage/
- tests/
- vendor/
public_html/
- css/
- js/
- images/
- js/
- storage/
(Laravel 8, trying to be hosted on Hostinger)
The tutorial : https://dev.to/pushpak1300/deploying-laravel7-app-on-shared-hosting-hostinger-31cj
Why does this problem happen?
If you implement and need storage matter in your project then you need to link storage folder to the public folder for security reason and to make the URL simple, clean and readable by the users, so when you upload the laravel project to a server, you need to run the following command line to complete the linking process:
php artisan storage:link
and since you host the laravel project to a shared server, so you don’t have access to a terminal to run the above-mentioned command line . so I’ll show you a way to do that manually without using SSH or the terminal.
Steps to fix the problem
1- At localhost server-side (before uploading the project to the server), make sure that you have done filesystem configuration, then run the following command line:
php artisan storage:link
after that you will get a message “The links have been created.” and that is ok for now.
2- Upload the project to the server, the storage link will not work as you expected, so we need to start fixing this.
3- Go to the public folder you will find a folder called “storage”, delete it.
4- Go to routes folder and open “web.php” file, then copy & paste the following code at the top of the file:
Route::get('/linkstorage', function () {
Artisan::call('storage:link') // this will do the command line job
});
Don’t forget to save the changes.
Also, you can do the same process via “api.php” and using requests tools like postman.
5- Now we just need to run this code, so we need to do the GET request by entering the following URL at browser search bar:
“https://www.your-domain.com/public/index.php/linkstorage”
or
“https://www.your-domain.com/public/linkstorage”
this request will run the above code “Artisan::call('storage:link')” which is, in turn, will run the command line
PHP artisan storage: link
now you can go to the public folder and you will see the “storage” folder created again and marked as a shortcut folder and that means the public storage folder now is linked to the storage folder of the project.
6- Now if you upload or create a file to the storage folder, then it will appear in the public/storage folder too, now you can hit the URL of the file at the search bar of the browser and you will get the file successfully :).
Ok guys i found the solution !
Here is how to deploy your Laravel project on one shared hosting using public_html folder : https://dev.to/pushpak1300/deploying-laravel7-app-on-shared-hosting-hostinger-31cj
This will work but you can have a problem (like me) with the storeAs() method if you deal with file uploads.
To solve this problem, I edited the MyProject/config/filesystem.php by adding this in the available disks :
'public_folder' => [
'driver' => 'local',
'root' => 'PATH',
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
]
Replace PATH with the complete path to your public storage (for example /home/you/domains/mydomain.com/public_html/storage/).
Now, open the controller which manage file upload and edit it like this :
request()->image->storeAs('/uploads', 'filename.png', 'public_folder');
This will upload the request()->image in public_html/storage/uploads/filename.png.
I hope it will help you if you had the same problem as me.
I created Laravel project and able to make it work to get json output as well. However image link in json is not working.
https://android.factory2homes.com/
json: https://android.factory2homes.com/index.php/api/products
image link:https://android.factory2homes.com/index.php/public/12142.jpg
i tried creating symlink and copied same image in storage folder as well, but not able to make it work.
The public folder in a Laravel project is basically the root folder that shows up on the website URL.
For security issues, you really don't want the users to have the ability to write anything directly on the public folder, because if you are not careful they could overwrite your php scripts and have them do whatever they want.
So generaly speaking you create a simlink inside the public folder to the storage folder that is outside the public directory. Laravel has even a built in artisan command to do that exactly which is:
php artisan storage:link
The URL to any image stored in that folder would be in your example:
https://android.factory2homes.com/storage/12142.jpg
You do not have to put any .php file, or public or anything else.
if the image is inside public then I don't think you need to give the url like index.php/public/someimage.jpg you can just do www.yousiteurl.com/someinage.jpg
I resolved issue by savings images to Public_html folder instead of public folder in Laravel app root folder. Public_html is the path that is visible to public, hence other solutions weren't working.
I am trying to accept an image in my frontend react app to my api and then store it back into a path within the frontend app however I get the following error:
Path is outside of the defined root, path:
[../../frontend/public/productimages/__test.jpg]
Basically I have used a multiform data to upload the image file.
If I do this: $file->storeAs('public', '__test.jpg'); Then the file is stored under Lumen backend directory but I would rather have in under my frontend directory.
When i log the base_path() in my Lumen backend API i get the following:
C:\Projects\website\backend
How can I instead store the image in:
C:\Projects\website\frontend\public
Try to store the file publicly like this:
$file->storeAs('productimages', '__test.jpg', 'public');
This way, you're file will be stored on storage/app/public/productimages. To make your file accessible from the web, you should create a symbolic link from public/storage to storage/app/public via artisan:
php artisan storage:link
Then you can access your file on public/storage/productimages which is accessible through web: http://your-domain.com/storage/productimages/__test.jpg
You can also manually create a symbolic link from C:\Projects\website\frontend\public to C:\Projects\website\backend\storage\app\public on windows cmd:
mklink /d "C:\Projects\website\frontend\public" "C:\Projects\website\backend\storage\app\public"
See Laravel docs for more info.
I have installed Laravel on /var/www/html/website but now I want to change storage path to /mnt/volume
So for doing this, I added this code in bootstrap/app.php
app()->useStoragePath('/mnt/volume/public/');
Now upload works fine, but after upload, a file new extra directory created like:
/mnt/volume/public/mnt/volume/mnt/volume/public/bookimages/77iF2Gdr7pKXXLRLovgIpfcKBxY1h7CRqKjc35SC.jpeg
which as you can see Laravel created mnt/volume/mnt/volume directory again.
Laravel Framework 5.5.44
Now, How can I solve this issue?
Create a custom disk in your filesystem.php config file with the root property set to your custom path instead
My Laravel Project works fine on my local machine but not on my online server .
On my Online server i have created a directory called dev and pasted entire laravel project inside it , so now the url to access routes are domain-name/dev/profile
but fetching an uploaded image which reside inside my public/storage/upload/image is giving me an error that image could not be found !!
Any Kind of Help is Appreciated !!
I think the issue could be with the Symbolic link. Run command php artisan storage:link using CLI.
If you don't have CLI access with your c-panel, you can run the command programmatically. Add below code in your routes/web.php file:
Route::get('/sym-link', function () {
Artisan::call('storage:link');
});
And visit YOUR-DOMAIN/sym-link once.
More info: https://laravel.com/docs/master/structure#the-storage-directory
If you are using Share Hosting First Check Link Path using
readlink -f storage
and if path is incorrect remove storage from public and create new symbolic link using :
ln -s ../storage/app/public storage
To Make sure link is created use ls and see if storage is in red color or not .if it is in red color then link created successfully. :)