i have the blade in this route:
/resources/views/cms/public/views/projects/showproject.blade.php
And the code to render the picture is this:
#if (Storage::disk('projects')->has($project->slug))
<p class="lead"><img src="{{ asset('/storage/projects/'.$project->slug.'/home.png') }}" width="50%" >Home</p>
#else
<p class="lead"><img src="/assets/img/projects/{{$project->slug}}/home.png" width="50%">Home</p>
#endif
The storage disk called projects looks like here:
'projects' => [
'driver' => 'local',
'root' => storage_path('app/public/projects'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
The error is this:
header.png Failed to load resource: the server responded with a status of 500 (Internal Server Error)
I think the problem is in the code on the view, i also read maybe i need use a symbolic link, isn't possible make it without?
Any help will be appreciated, if have any question ask it please.
Thanks. (I check the others question of stackoverflow before, and can't find the error).
From the Documentation https://laravel.com/docs/5.4/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.
To create the symbolic link, you may use the storage:link Artisan command:
php artisan storage:link
Of course, once a file has been stored and the symbolic link has been created, you can create a URL to the files using the asset helper:
echo asset('storage/file.txt');
Related
When I run in my local, the image file is shown. But in the production server it is not showing.
URL in my local :
http://localhost:8000/files/image/GOT7.jpg
URL in my production server :
http://myApplication.com/files/image/GOT7.jpg
.env in the local :
APP_URL=//localhost
.env in the production server :
APP_URL=https://myApplication.com
config/filesystem.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('/app'),
],
],
file location in the folder public/files/image/GOT7.jpg
How to solve it?
I'm gonna take a guess here and say that it is a symbolic link problem.
https://laravel.com/docs/8.x/filesystem#the-public-disk
You are using a filesystem named local which has its root in storage_path('/app'). This is a reference to the storage directory in your Laravel project.
This directory by default is not accessible. Nor should it ever be. Only your public folder should be accessible from the internet (so everything goes through public/index.php only).
So a solution that Laravel offers is to place a symlink in your public folder to a particular storage path. See the link above.
php artisan storage:link
This would create a symbolic link for you in public/storage to storage/app/public. This should now make your files accessible. For more finetuning see the Laravel docs link above.
I'm trying to set-up a laravel cms system that already exists on a shared host. But when i setup my laravel project on this shared hosting directory i get the error
symlink() has been disabled for security reasons
I can't seem to find a proper explenation on how i can fix this in my situation. I only get this error the first time and when i refresh this error, it disappears.
in your project's public directory, manually create a storage folder.
this worked for me
You can create symlink for your desired directory by logging in to your server via SSH download Putty and then login to your server via putty by using your server credentials. You can use linux commands to create a symbolic link:
ln -s TARGET LINK_NAME
Where the -s makes it symbolic.
There are 2 options to solve this;
Use any of the supported services for file storage i.e Amazon S3, Dropbox, FTP, Rackspace
Follow the steps below;
Create a folder in /public folder named /storage
Move all folders from /storage/app/public/ to the folder you created /public/storage/
Open file config/filesystems.php and change the values as shown;
'local' => [
'driver' => 'local',
'root' => public_path('storage'),
],
'public' => [
'driver' => 'local',
'root' => public_path('storage'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],
Now open file .env and change or create the values as shown below;
AVATAR_DIR=avatars
SIGNATURE_DIR=signatures
LOGOS_DIR=logos
MEDIA_DIR=media
After a lot struggle this trick work for me at shared hosting server for Laravel project.
Connect with terminal at server via SSH or directly from CPanel
Run this command at your terminal
ln -s /folder-path-with-name-to-be-linked /folder-paht-where-you-want-to-link-it
e.g in my case
ln -s /home/user-name/public_html/domain-folder-name/storage/app/public /home/user-name/public_html/domain-folder/public/
Note: You don't need to change in php.ini and .htaceess files.
Reference Link:
https://unix.stackexchange.com/questions/141436/too-many-levels-of-symbolic-links/141442#141442?newreg=14b52f3d6fcb454399a1a1a66e2170df
The problem could be that your hosting provider will not let you create the smlink.Have you checked if this is the case?
One suggestion if so, is to write the files that you would have put in the symlink folder directly into the public area of the site so that a symlink is not required.
I'm trying to store and show image for my app. Image storing properly but failed to show.
First I created symbolic link using command: php artisan storage:link
config/filesystem.php look like:
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
to store image:
if($request->hasFile('avatar'))
{
$path = $request->file('avatar')->store('avatars');
//$path=avatars/generated_image_name.extension
$user->avatar=$path;
$user->save();
}
//image storing under: (../storage/app/avatars)
to display image to view:
<img src="storage/{{$user->avatar}}"
alt="no image!!"
class="img-circle"
style="width:150px;height:150px;">
tried src="storage/app/{{$user->avatar}}" & src="{{$user->avatar}}"
but can't fetch image. Don't understand what I'm doing wrong.
Hate to be that guy, but have you read the docs. You need to create a symbolic link from public/storage to storage/app/public.
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.
To create the symbolic link, you may use the storage:link Artisan
command:
php artisan storage:link
Edit
Again I would check out the docs or maybe read them :).
I think your default storage is local and not public. In config/filesystems.php look at the default driver.
Storing Files > File Uploads > Specifying A Disk
or try something like this.
if($request->hasFile('avatar'))
{
$path = $request->file('avatar')->store(
'avatars/'.$request->user()->id, 'public'
);
//$path=avatars/generated_image_name.extension
$user->avatar=$path;
$user->save();
}
I am using laravel 5.4. I upload some document file in storage/app/public/documents folder like
$request->paper_file->store('documents');
and my file uploaded successfully.
in file system default storage is public
and public conf is like
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',],
but when i hit /storage/documents/hQqlgifnVVH8bmrRPVdZ9aFGbhLmcc7g7bHZSX4u.pdf
it says not found 404. How to solve this issue.
By default Laravel puts files in the storage/app/public directory, which is not accessible from the outside web. So you have to create a symbolic link between that directory and your public one:
storage/app/public -> public/storage
You can do that by executing the php artisan storage:link command (docs).
This problem happen to me after moving project to different folder.
If you already have storage link generated, try to delete public/storage folder and run again:
php artisan storage:link
In laravel ^5.8:
Make sure you run the command php artisan storage:link to link storage/app/public with public/storage.
now:
// this return some like 'public/documents/file.ext'
$path = $request->paper_file->store('public/documents');
// this return some like 'storage/documents/file.ext'
$publicPath = \Storage::url( $path) );
// this return some like '< APP_URL env variable >/storage/documents/file.ext'
$url = asset( $publicPath );
When you upload an image with Laravel's storage function it is stored in a storage folder.
For example:
storage/app/public/avatars/file1.png
But when you want to access it via URL, you should access it like this:
storage/avatars/file1.png
It worked for me, using Laravel 7.x.
If you are coming from laravel 8.x and have indeed ran the command php artisan storage:link(to create a symbolic link ), but your code is not working i.e the file you are trying to load is not displaying, then you are like me.
Just awais ahmad mentioned, This solution porved helpful with my laravel 8x project. I have not added the "storage" path name from my blade file with the asset helper function so my image path was not outputing anything but when I typed the 'storage' path name like so asset('storage/uploads/pic1.png) my code worked!
Guess this might help someone.
After running php artisan storage:link it creates a symbolic link in the public folder and you can retrieve record like so <img src='{{ asset("public/$advert6") }}' class="img-responsive">. You should include the public directory
In my Laravel 5.1 app, I'm storing images in storage/app/uploads folder.
My local disk:
<?php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app/uploads'),
],
// other configuration...
?>
Thing is, I can't figure out a way to use the image files after they're uploaded, e.g. as the source of <img> tag. Basically, I need to retrieve a valid path to an image, so it can be used on the page.
For deployment I'm using Envoyer which provides a solution. According to Envoyer docs:
When storing user uploaded files, you should store them in the storage directory of your application if you are using Laravel. Then, you may use the "Manage Linked Folders" feature of Envoyer to create a symbolic link from your public directory to the storage directory. The "Manage Linked Folders" button can be found on the "Deployment Hooks" tab of your project.
..and this is clear.
But how do I "link" the storage and public folders in my local development environment? Does Laravel provide a way to do it, or do I need to create a symbolic link in my environment manually?
There are a few options:
Create a controller that would output the files
class AssetController {
public function show($id) {
$file = File::findOrFail($id);
return Response::make(Storage::get($file->storage_key), 200, ['Content-Type' => $file->mime_type]);
}
}
Create a symlink public/assets => storage/app/
Upload files to public/assets instead of storage/app
Use rewrites on your web server to serve the files from your storage/app folder - how to do that depends on what webserver you are using. For nginx you could use something like
rewrite ^/v1/assets/(\d+) /../storage/app/$1;