Can't retrieve images from storage in Laravel 5.8 - php

I can't retrieve images from storage and I don't know why. I tried many ways but not working. I ran the following command:
php artisan storage:link
I tried these but none of it worked :
<img src="/storage/images/{{$slide->image}}" class="d-block w-100" alt="...">
<img src="{{asset('/storage/images/'.$slide->image)}}" class="d-block w-100" alt="...">
<img src="{{Storage::get('public/images/', $slide->image) }}" class="d-block w-100" alt="...">

php artisan storage:link creates a symbolic link from public/storage to storage/app/public.
So you have to call public/storage/images/ to access the image.
So in your blade you need to link the source to something like this:
<img src="{{ asset('storage/app/images/'.$slide->image) }}"></img>

$url = url('storage/app/public/images/') . $variableName;
<img src='.$url.'>

Related

Image not showing in .blade file

I'm new to Laravel, but why the hell is this not working?
<img src='../img/netflix_logo.png' />
I've tried using php artisan storage:link and it said The [C:\xampp\htdocs\laravel-crud\public\storage] link has been connected to [C:\xampp\htdocs\laravel-crud\storage\app/public]. The links have been created. but the image is still not displaying in my .blade page..
If you image is in storage/img then
<img src="{{ url('storage/img/netflix_logo.png') }}" alt="" title="" />
If you image is in public/img folder then
<img src="{{ URL::to('/') }}/img/netflix_logo.png" alt="" title="" />
You probably need to use the "asset" helper from laravel/blade:
asset('/path/of/your/image')
It's the common way to call a static file from public folder (including storage if you already linked it)

problem while trying to display image from database

I am trying to display a row from my database by id, the data displayed successfully but the image doesn't show (showing a broken link icon).
Here is the index.blade.php where the href to the row:
<a href="singlepost/{{$products->id}}">
<img src="storage/{{$templates->image_path2}}">
The route:
Route::get('/singlepost/{id}', 'App\http\controllers\TemplatesController#getPostById')->name('single.post');
The function getPostById
public function getPostById($id){
$products = DB::table('templates')->where('id', $id)->first();
return view('singlepost', compact('products'));
}
The singlepage.blade.php
<div class="row">
<div class="col-lg-4">
<img src="storage/{{$products->image_path}}">
</div>
<div class="col-lg-7">
<h2>{{$products->name}}</h2>
<p>{{$products->description}}</p>
</div>
</div>
When referencing publically accessible files, you want to do so from the /public/storage directory. Files from the /storage/app/public directory should be mapped from this directory to /public/storage using a symbloic link,
You create the symlink using:
php artisan storage:link
With that done, assets in /storage/app/public can now be accessed as if they existed in /public/storage. Use the asset helper to get your image.
<img src="{{ asset($templates->image_path2) }}" alt="Some alt tag ..." />
The above assumes a relative path of the asset from the /public/storage root, if you had the image in a subdirectory you would need to include that too.
For example, if you had your images in an img subdirectoy:
<img src="{{ asset('/img/' . $templates->image_path2) }}" alt="Some alt tag ..." />

How to Display Saved Images in Laravel 5.5?

I am trying to show stored images in img element. I have saved an image by using a Laravel built-in function.
$path = $request->file('image')->store('avatars');
According to the above script, the images are saving to:
Storage > app > avatars
I also tried saving them here:
Storage > app > public > avatars
Afterward, I used the Artisan command: php artisan storage:link
And then in the front end:
<img src="{{ url('storage/'.$Product->image) }}" width="30" height="30"/>
<img src="{{ asset('storage/'.$Product->image) }}" width="30" height="30"/>
<img src="{{ asset($Product->image) }}" width="30" height="30"/>
<img src="{{ asset('public/storage/'.$Product->image) }}" width="30" height="30"/>
However, the image is still not displayed. Can someone kindly let me know where I'm wrong so that I can fix it? I would appreciate that.

Wordpress images don't get displayed

I started to learn Wordpress and I'm making my own theme. Within the design I have some images that are supposed to show up... but they don't.
I was using this code:
<div class="col-xs-4">
<img src="images/html_brand.jpg" class="img-responsive">
</div>
and then I found I should use php to link to my image:
<div class="col-xs-4">
<a href="#">
<img src="<?php bloginfo('stylesheet_directory'); ?>html_brand.jpg"
class="img-responsive">
</a>
</div>
But the problem is, the image still doesn't get displayed. And yes I did upload them to my web server. I have them in the directory of my theme: mythemename/images/html_brand.jpg
If you use bloginfo() to output your theme path, you need to add another /, followed by the remaining path to your image. Based on where you've placed your image, this should work:
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/html_brand.jpg" class="img-responsive">
However, bloginfo() ultimately relies on get_template_directory_uri() to work, so you might as well just use that:
<img src="<?php echo get_template_directory_uri(); ?>/images/html_brand.jpg" class="img-responsive">
Slight Correction:
bloginfo() with the specific argument of stylesheet_directory actually relies on get_stylesheet_directory_uri() to function -- get_template_directory_uri() like I originally said.
https://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/general-template.php#L439

How to do this in codeigniter?

Does anyone know how to make resize.php to work in codeigniter?
Below is my code used before CI and it worked perfectly fine before I decided to upgrade, now I'm facing this issue.
<img class="media-object" src="funcs/resize.php?src=customers/400.jpg&w=60" alt="...">
I have tried the code below, but with no luck!
<img class="media-object" src="<?php echo base_url();?>funcs/resize.php?src=<?php echo base_url('customers/400.jpg'); ?>&w=60" alt="...">
I also gave this a try:
<img class="media-object" src="<?php echo base_url();?>funcs/resize.php?src=<?php echo base_url();?>customers/400.jpg&w=60" alt="...">
I am new to CI and I don't know what else to try.

Categories