Image not displaying correctly in Blade Laravel template - laravel

I need to generate qr-code and for this I use this package https://github.com/SimpleSoftwareIO/simple-qrcode
qr-code is generated in png format and I save it to the right place in the file system. Also, I write the path to this file into the database. The file path is always '../storage/app/public/' . Auth::user()->id . '/qr.png'. Every time a new file is generated, I overwrite the old one.
The problem is this. In the template, I am trying to display this image in the saved path and it is displayed but not correctly.
For example, I have a qr-code in a template, next I generate a new one and expect to see it, but the old image is displayed, which has been overwritten. Normal reloading of the web page does not help. Everything works correctly if you reload the cntr+f5 page
Is it a cache issue or something else?

I think it's not a laravel issue, it's a browser "feature".
Have you tried to add a parameter to the image path to force browser do not cache the response?
<img src="{{ url('/storage/' . Auth::user()->id . '/qr.png?v=' . time()) }}" alt="My newest QR code">

Related

GET imageRoute 404 (Not Found) on Laravel

I have a Laravel project that I've mainly been working on it's back end, but now I copied the layouts from another project which has two images on the header. This is one of them:
<img class="img-logo" src="imagenes/temp_imgs/logo temporal.png">
The images on my old project are stored on public/imagenes/temp_imgs/, so I created those same folders on my new project and stored the images there. But when I run it I get the following error:
GET http://localhost:8000/competencias/imagenes/temp_imgs/logo%20temporal.png 404 (Not Found)
It seems as if it isn't looking for the images on my public folder but rather on the location of the view (competencias), the view is competencias/crear.blade.php
I don't remember much from the configuration on the old project, I only now I ran npm install on both at creation, so both have bootstrap and vue. But that's al I now, maybe you can help me see if a configuration file on the old project is making the image src point to the public folder, or figuring out what's generating the error.
EDIT:
If I paste one of the files from my old project to my new one the images are shown. If I rename one of the files from my new project and give it a name of a file from my old project the images are also shown! I hope this helps in figuring this thing out.
in laravel 5.4 you will not able to see image as your link
route will lock your every public folder
http://localhost:8000/competencias/imagenes/temp_imgs/logo%20temporal.png
just try to use like that
<img class="img-logo" src="{{ url('imagenes/temp_imgs/logo temporal.png') }}">
or
<img class="img-logo" src="{{ asset('imagenes/temp_imgs/logo temporal.png') }}">
You should use {{ asset('imagenes/temp_imgs/logo temporal.png') }}
For all assets use {{asset(....)}} to solve all problems that maybe appear for you
Hope help you

Codeigniter Mpdf image not shown in header

I've a problem with mpdf and Codeigniter: i'm printing an html page right if I load just simple text.
If I add an image in my header by
$mpdf->setHTMLHeader(site_url("assets/img/my_image.jpg"));
The browser load for minutes and then download a pdf file with a red X intead of my image. It seems my image link is broken, but it's not: i've checked it.
I've thought it could be a permission issue so I changed my img folder's and files permissions to 777, but nothing has changed...
Any ideas on how to solve it?
I think that problem is in relative path for image, even if the web browser is fine with them and display the images correctly.
Try to generate a path with an absolute base URL.
<img src="full_path/assets/img/my_image.jpg', true) ?>" alt="my_image" />
Or try to use base64 image.
Also you can set debug to true and see what is error (sometimes is GD extension)
$this->_mpdf->showImageErrors = true;

how and where can store images with laravel?

how and where I can store images using laravel?
context:
I want display some images in my main view (these are predefined by me).
I also want to store images uploaded by users, however, do not know where to store these images.
I'd like to call these from the view...
Thank you very much for the help. :)
Basically you can save your files wherever you want within your Laravel application provided that you have permissions to create directory and file.
But I prefer saving files in the storage/app folder. Laravel provides a simple API to manipulate files on disk. See the docs.
Update:
This answer was posted when Laravel was in version 5.2.
From version 5.3 on, you can easily create symbolic links by running the artisan command php artisan storage:link. See the docs.
Make directory for images in myapp/public/images and keep images on there.
<img src="{{URL('/images/logo.jpg')}}">
If you want to display them on your site store them in your public directory. Since they are uploaded by users you will need to pass them through a form. Here is an example of a controller.
$file = Input::file('picture');
$file->move(public_path().'/images/',$user->id.'.jpg');
The user will submit a form with a picture field. The two lines above will store it in the public directory in an images folder, with the relevant user's id as its name. Your probably best off making a model in your database for images and their paths. If you do, add these lines after the two above.
$image = new Image;
$image->path='/images/'.$user->id.'.jpg';
$image->user_id = $user->id;
$image->save();
To display it in the view simply set an $image variable to the correct image model in your controller and pass it to the view. Then pop its path in the src of the image.
<img src={{$image->path}} alt={{$image->path}}>

Joomla alters the path of the images included in an article

I'm new to joomla and doing some changes to an existing website designed using Joomla.
Given below is a line that I've inserted to an existing article
<img SRC="images/myimages/demo/IM-0002-0025.jpg" class="highlighted" data-value="image_value"/>
but it does not display the image when I view it on website. When I view the source of the image in the webpage it shows below
<img src="http://xxxxxxx.cloudfront.net/images/myimages/demo/IM-0002-0025.jpg" class="highlighted mTSThumb" data-value="image_value">
My JPATH_BASE is http://localhost/mywebsitename/
but still it appends "http://xxxxxxx.cloudfront.net/" to the image path
I've even enabled the URL rewrite as mentioned in the joomla prepends to 'path'
But still it didn't change anything. Please help
It's been a while since I've used joomla but I'm sure you have to begin the line with a forward slash to before images.
<img src="/images/"
This makes it relational to the site.
I'm not sure whether this is a hack or not. but I've managed to fix the issue by specifying the image path followed by a ./
So now the image path looks like this and it works fine.
<img SRC="./images/myimages/demo/IM-0002-0025.jpg" class="highlighted" data-value="image_value"/>
Yes that looks right. Mark your answer as complete

laravel - image upload and display issues

I have a blog post application where I am uploading files to be displayed along with the post itself. I can successfully upload the image but I am unable to display it .
Here is how I am uploading it to a folder within my application..
and here is how i am displaying it..
I am uploading the image to the uploads folder under my public folder. and I am storing the image in the database as follows..
Although I can see that the image path is correct. I did an echo of the path that is being generated and the path to the image is correct.
Can you please let me know if there is something that I am doing wrong.
thanks
Change
$file = $file->move(public_path() . '/images/uploads', $filename);
to
$file = $file->move('images/uploads', $filename);
the above code will upload the picture to the public_path/images/uploads.
In your code, i can see you have used full physical path of your image directory to display the picture. Physical path only needed when you are going to upload an image.
try the following:
<img class="img-responsive" src="/images/uploads/{{ $post->thumbnail }}" >
You are storing the thumbnail within the post model, but are trying to fetch it form the blog model. Try $blog->post->thumbnail instead. (If you have set a relationship)

Resources