Can not display the image which its path comes from database - codeigniter

I have a form which successfully upload a picture to a folder and save its full path to database.But when I want to display the image nothing is shown.
This is one of the uploaded image's path in database:
/home/webuser/public_html/traincms/upload/koala.jpg
this image saved in a folder of server.what should I do to display the images?
Thanks for your help.

You should use HTTP path of image, if you are using codeigniter then try this way
<?php echo img("traincms/upload/koala.jpg"); ?>
OR
<img src="<?php echo base_url("traincms/upload/koala.jpg")?>" />
Hope your code will store in public_html directory

Finally I found the solution.My upload path was
$path=dirname($_SERVER['SCRIPT_FILENAME']).'/upload/';
I saved this path to database.When I want to display the image on browser it did not display it with this path.I uploaded the image with above path but I saved this path to database:
$image_path=base_url().'/upload/'.$_FILES['pic']['name'];
now I can upload and display the images successfully.

Related

Image not loading in Thymeleaf

I'm trying to load an image from my project's local storage in email with Thymeleaf but it won't !
<img src="../static/img/logo.png" alt="MyPicture" th:src="#{img/logo.png}">
although when I try with an absolute path it's perfectly loading
<img src="C:/Workspace/myProject/src/main/resources/static/img/logo.png" alt="MyPicture">
My images are stored in static/img
The image path shall start with a forward slash like
<img alt="MyPicture" th:src="#{/img/logo.png}">
try changing your path to
<img src="img/logo.png" alt="MyPicture">
and you might also want to invalidate cache from your IDE settings for the image to be detected

I want to display images in my views in laravel

I am trying to create a blogging application with Laravel and so I got this in my view
<img src="{{$post->image}}" />
the image is not showing up but the post title shows up.
I tried:
php artisan storage:link
and its return:
The "public/storage" directory already exists.
but yet still no image displays
Based on your comment, you upload the image to a private storage folder so it's will never show. You should upload to the public folder using code like this:
$image = $request->image->store('posts','public');
then if you want to show it just use <img src="{{url("storage/".$post->image)}}" />

Image isn't visible in my site

I've just added a simple code (<img src="images/2.jpg"/>) in my WordPress website. But it's not working. Check it out
Please help me to solve the issue.
Try add leading slash to your image path to start at the root directory instead of your current directory where your code is located:
<img src="/images/2.jpg"/>
most likely the path is incorrect. images is not immediate directory to your current page directory.
usually in wordpress images are in wp-content/uploads/2017/05/%some_image.jpg%
you are using <img src="path"/> you can solve this issue by adding the url of the image like ‪C:\Users\Hitesh Kumar\Desktop\xyz.jpg.
but i know that you are using wordpress so you can add the image by its url like <img src="www.site_name/image.jpg"/>
hope it will help
Need to add this code (<?php echo get_template_directory_uri();?>) to make it dynamic.

CMS image is not showing properly with WYSIWYG

When I add an image with the WYSIWYG-editor, the image path is to long. I get the following path:
<img src="media url="home/magento/static/media/wysiwyg/people.png"" alt="" />
Instead of:
<img src="media url=wysiwyg/people.png"" alt="" />
When I import the image URL, I get in the WYSIWYG pop-up the following image URL:
The image URL is as follow: https://server.magento.local/index.php/smladmin/cms_wysiwyg/directive/___directive/e3ttZWRpYSB1cmw9ImhvbWUvc2FuaWRpcmVjdC9zdGF0aWMvbWVkaWEvd3lzaXd5Zy9sb2dvLXBpbi5wbmcifX0,/key/acc4e19a8864aa88801f17ea0d3d8b3e/
I think the problem has something to do with the Symlinks? Because it is only on our server, not in our local environment.
How could i solve this issue?
Thanks
I found the answer in another post: How can I relocate my magento store's media directory?
--
Can add as symbol links,
but you will get some problem with WYSIWYG editor in admin panel :)
Need following:
edit /app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php
function getCurrentUrl()
$path = str_replace(Mage::getConfig()->getOptions()->getMediaDir(), '', $this->getCurrentPath());
change to
$path = str_replace(realpath(Mage::getConfig()->getOptions()->getMediaDir()), '', $this->getCurrentPath());

Image display codeigniter fails

I can upload image to the directory but can not disply it on the page.
Tried using static html code and codeigniter img() function, both are not working.
Here is my code:
<image src="./applications/views/uploads/image.jpeg" />
and
$this->output->set_header("Content-Type: image/jpeg");
$data['image'] = $this->load->file('../uploads/taurus.jpeg');
the first code shows me broken image the second one shows Unable to load the requested file: taurus.jpeg
<image src="./applications/views/uploads/image.jpeg" />
By default, CodeIgniter denies access to the application folder which is why I suspect this isn't working.
$this->output->set_header("Content-Type: image/jpeg");
$data['image'] = $this->load->file('../uploads/taurus.jpeg');
I suspect this isn't working because your path is incorrect. The path is relative to the index.php file in the root of your application, not the file this code is in. Secondly, $this->load->file() sends to file contents to the browser so this wouldn't work anyway.
A solution would be to move your uploads folder to a web accessible location. For example, place the uploads folder into the root of your application - the same folder as your index.php file. Then you can display your image like this:
<image src="/uploads/image.jpeg" />
Just get rid of the dot (.) in the URL so your src url reads: "/applications/views/uploads/image.jpeg"

Resources