Response() in laravel 5.6 look up folder - php

I'm using laravel 5.6 and using the following code:
return response()->file($pathToFile);
My problem is I cant seem to find what folder pathToFile is pointing to. I tried the public/folder, but that doesn't appear to be it.

Laravel stores files under /storage which is by default hidden to public.
If you want to make them publicly available you need to issue command php artisan storage:link
After that all your files in your /storage directory will be accessible in your http:/domainname/storage via for example asset('storage/yourfile');

Related

Laravel 404 error while viewing image saved in public directory of laravel project

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.

Laravel filesystem, How to set public file only can view by after login

Laravel 5.7
PHP 7.2
DB mysql
already see https://laravel.com/docs/5.7/filesystem
I am using the Local Driver.
after some process, I have set a image to public file.
e.g.
https://127.0.0.1/storage/myViewFile/0120020301-3.png
I want to set only can view dir "myView File" after login.
How can I do it? thank you.
Route::get('/storage/files/{file}', 'FilesController#show')->middleware('auth');
and in the show method display the image.
If you were to use your local driver and would want to make files accessible in your storage folder then you would run an artisan command like below
php artisan storage:link
This will ensure that files are accessible publicly as example.com/public/storage/whateverfile. However, if you want the files to be only accessible to authenticated user then may be you can put the files in storage/myViewFile which will make sure that files in the folder aren't publicly accessible. Then using a controller with an auth middleware or route with middleware you can make files accessible

Laravel Storage Linking is not working using symlinks command

I have uploaded my Laravel Web application to my server and tried to run the symlinks command but the media/images are not syncing. Anyone here can help me how to fix the storage issue?
here is my symlinks command :
<?php symlink('/home/webcxsol/shog/storage/app/public','/home/webcxsol/public_html/storage'); ?>
My public folder is in the public_html folder of the server and all the other files are in the other folder.
If you are or wish to follow the framework conventions, there is a specific command for this which you could take a look at using: php artisan storage:link.

Issue with key (cipher error) when changing laravel folder structure

I am changing laravel 5.3 folder structure. What I exactly do is basically move all the content from public folder to root folder, and then all the other files besides public folder to the new created folder - project. Then I update the require paths in index.php, and when I try to run the project via XAMPP, I'm getting this error.
I am pretty sure that the key is set correctly, because I haven't changed anything else but the folder structure and paths, and the project worked before this folder structure change. It seems to me that program can't locate the .env file.
Try running
php artisan config:clear
and
php artisan key:generate
I followed this post

Routes file not properly loaded

I have just installed a new installation of Laravel using composer as per the laravel docs. The documentation refers to the app/routes.php file which is used to map routes to controllers or closed functions. First, there was no app/routes.php file so I created one. Now the routes I've copied from the laravel documentation aren't being found when accessing via the browser. In fact the app/routes.php file isn't even being found by the application as I have put a die statement in there and nothing. It has nothing to do with .htaccess. I am using the default .htaccess and redirects are working. I thought maybe it has something to do with the composer.json autoload array so I have tested that and nothing. Not a jot. Either I'm being thick or there is something fundamental which isn't being explained in the docs. I'm running the latest version of laravel. Any ideas?
Laravel changed the folder structure with its latest release (which is version 5):
In 4.2: app/routes.php
In 5.0: app/Http/routes.php
There's also a few things you need to do in order for a Laravel Project to work. First (and this is the method I use) create a symbolic link to your project's public folder:
ln -s /path/to/webroot/example_app/public /path/to/webroot/example
Next, change the permissions on your storage folder:
chmod 777 -R storage
You should now be able to access localhost/example and the Laravel 5 welcome page should show up. Usually I call my project example_app and create a link to a folder called example, so I can easily access it via localhost/example
In Laravel 5, the routes file is located elsewhere: app/Http/routes.php.
Basically I did chmod 777 on the storage and vendor files and it started working

Categories