How to Access the Storage File - laravel

How to Access the Files in Storage.
File Location
storage/uploads/documentUpload/3_1620028799.PNG
Remember : php artisan storage link will not works because files are not in app/public folder.
File URL http://example.com/storage/uploads/logo/logo.png 404 error.
is any way to overwrite in htaccess?
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

You can create a new disk in your config/filesystems.php, for example uploads
'uploads' => [
'driver' => 'local',
'root' => storage_path('app/uploads'),
'url' => env('APP_URL') . '/storage/uploads',
'visibility' => 'public',
],
and at the end of config/filesystems.php file, add a new symlink for uploads folder
'links' => [
public_path('storage') => storage_path('app/public'),
public_path('storage/uploads') => storage_path('app/uploads'), // Add this
],
Then run php artisan storage:link
Whenever you want to get the url of file, just run
\Storage::disk('uploads')->url('documentUpload/3_1620028799.PNG');

Related

Laravel 7: External link not working in localhost

The external links of CSS and JS are not working when I try access my Laravel project from localhost by www.localhost/myproject this. But others porject run well. I have to run php artisan serve command to run my project perfectly. When I upload it to Cpanel hosting it shows the error This site can’t be reached.
This is the app URL in env file APP_URL=http://localhost
This is how I declare the links {{ asset('backend/mystyle.css') }}
All of my CSS, Js files are under public folder. I think there might some problem in .htaccesss.
File structure:
-app
-public
--backend
--css
--robots.txt
--web.config
-.env
-.htaccess
-index.php
-server.php
.htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /hrm-payroll-v3-2021/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
AddHandler application/x-httpd-php70 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php70/lib
</IfModule>
Index.php file
<?php
define('LARAVEL_START', microtime(true));
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
Server.php file
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/index.php';
Can you please tell me why this problem may occur? What is the possible solution to this problem?
Thanks
you need to change your APP_URL to your domain
If you run php artisan serve without any arguments, Laravel starts a local web server on port 8000. Therefore you should consider this in your .env file by adding the port number in your APP_URL.
When you upload your project to a cpanel, make sure the web server is referring to YourProject\public as document-root directory.
I have solve my problem with updating htaccess file.
htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Options -MultiViews -Indexes
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images|trainer-cv)/(.*)$ public/$1/$2 [L,NC]
then rename the server.php file to index.php

Laravel request->all() shows array with page url

I am sending a GET request to a route and I am getting back weird response when using
dd($request->all());
my route is
Route::get('{brand}/{type?}/{city?}', 'SearchController#index')->name('search');
my url is link/toyota?page=1 and the response back is
array:1 [▼
"/toyota" => null
]
I would like to mention that it is working on localhost using serve, but I am hosting this on cpanel
Edit : All query strings on my website does not work...
It was a problem with htaccess...
Cpanel changed my htaccess
if anyone comes here for the same reason, the default laravel htaccess is
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

uploading laravel project on subdomain on a live server

I am trying to upload my laravel 4.2 project to live server. I have a domain( example.com). And I have subdomain(subdomain.example.com). This is my root directory.
All files are in blog_files except public folder. My public folder is in public_html/blog/ . I have changed two lines of my index.php as:
require __DIR__.'/../bootstrap/autoload.php';
to
require __DIR__.'/../../blog_files/bootstrap/autoload.php';
and
$app = require_once __DIR__.'/../bootstrap/start.php';
to
$app = require_once __DIR__.'/../../blog_files/bootstrap/start.php';
error occured while trying to open the url(subdomain.example.com)/
Error:
Any help would be appreciated.
Note: I am following this suggestion.
deploy laravel 4 app in a subdomain
In your bootstrap/path.php
'app' => __DIR__.'/../app',
'public' => __DIR__.'/../public',
'base' => __DIR__.'/..',
'storage' => __DIR__.'/../app/storage',
Change these lines to
'app' => __DIR__.'/../../blog_files/app',
'public' => __DIR__.'/../../public_html/blog',
'base' => __DIR__.'/../../blog_files',
'storage' => __DIR__.'/../../blog_files/app/storage',
EDIT:
Do not put public folder in directly in your public_html/blog. Just put the contents of the public folder in public_html.
And also use below as your .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Try this:
Don't modify laravel files, just add an .htaccess inside blog/
File: /home/vijayrana/public_html/blog/.htaccess
RewriteEngine On
RewriteRule ^(.*)$ /public/$1
And point subdomain.example.com to /home/vijayrana/public_html/blog/

Laravel 4 admin route same as admin folder

i have an /admin folder and i cant delete becaus there are old files linked externaly and i need to use the /admin route.
When i use the /admin route i have a loop, if i rename the admin folder, it works, but i cant do that permanently.
If i use another route like /admin/anything, it works.
How can i have the folder and the route work together.
Here are my routes:
Route::post('admin/login/valida', ['before' => 'csrf', 'uses' => 'LoginController#getValidar']);
Route::get('admin/login', 'AdminController#Login');
Route::get('admin/asociarmenuarchivo', 'AdminController#Asociarmenuarchivo');
Route::get('admin/disenosnuevos', 'AdminController#disenosNuevos');
Route::get('admin/disenosnuevooantiguo', 'AdminController#switchDisenos');
Route::get('/admin', 'AdminController#getIndex');
The last one is the only route that doesnt work.
Here is my .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
# RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/cm/.*
#RewriteCond %{REQUEST_URI} !/admin/.*
RewriteCond %{REQUEST_URI} !/correo/.*
RewriteRule !^/?admin index.php [L,QSA]
RewriteRule ^ index.php [L]
ErrorDocument 401 "Unauthorised"
</IfModule>
The problem was the slash rewrite, the solution was:
RewriteCond %{REQUEST_URI} !/admin/.*
RewriteRule ^(.*)/$ /$1 [L,R=301]

Kohana 3 deployment controller problems

I have recently migrated my app from a windows localhost up to a linux host.
My problems is that I can't access a controller, I always keep getting the message: File not found.(From the web server)
And this is odd because the same code base is working on my localhost.
bootstrap.php:
Route::set('default', '(<controller>(/<action>(/<id>)(/<param1>)(/<param2>)))')
->defaults(array(
'controller' => 'user',
'action' => 'index',
'param1' =>'',
'param2' =>'',
));
.htaccess:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
The odd thing that happens here is that if I go to :
www.myapp.com/ then the default controller executes and it finds the user/index function.
But if I manually write it as www.myapp.com/user/index I keep getting the File not found message.
I have tried renaming the controller files with lowercase so I guess thats not the problem, besides if that would be the problem, the default route wouldn`t find it in the first place, right?
If for example I write in the default route:
Route::set('default', '(<controller>(/<action>(/<id>)(/<param1>)(/<param2>)))')
->defaults(array(
'controller' => 'user',
'action' => 'login',
'param1' =>'',
'param2' =>'',
));
And I accesss www.myapp.com , it would load the user function. I can't figure out what is wrong here, why when I write myapp.com/user/login it says file not found, but if I put it as the default route it opens it.
did you set the base_url in bootstrap.php? if no, you should set the base_url your_project_name/
if yes, you should set the RewriteBase /your_project_name/ also in your .htaccess
I found the solution in another thread related to this. You need to add this chunk of code into .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Hope it helps the others !

Resources