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)
Related
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">
I save images in a controller with the $imagePath = "/upload/images/{$adver} address. Then these images are saved in a public folder in the root folder, but when I move these images file into the C-Panel I can't see them.
The address of an image is saved in advertise table and the images are saved in the public folder. I use src="advertise.image1" to show an image.
The images are in a database and I get the route to database to show them on the website.
Are you using the public_path helper function?
$imagePath = public_path("/upload/images/{$adver}");
You may have issues with your public path if you're saying they're not working on the remote location. Is your remote public path set as public_html rather than public?
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;
I am having a problem with accessing images.
I can upload and receive an image to the database no problem; however, I have my images manually saved under the public/avatar folder and I can retrieve the images from that location by using:
{{ asset('/uploads/avatars/image.jpg }}
I cannot figure out how to save to that location; I've tried the following to no avail:
Storage::disk('local')->put('/uploads/avatars/', $image);
Also, when I try to save from the controller it saves everything in storage/app/public, but I don't know how to access the image files from the model nor how to save them somewhere else.
When you use this
Storage::disk('local')->put('/uploads/avatars/', $image);
then all of your images are store in storage/app/uploads/avatars directory. so you can not access it from public directory. If you want to access it from public directory, you have to make a symbolic link of storage/app/uploads/avatars in public directory. I think it work fine :)
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}}>