0

<img> tag is not working in PHP Codeigniter

<img src="<?php echo $p_info['p_img']; ?>" alt="Product Image is not uploaded" height="700px" width="500px" />

Output of $p_info['p_img'] is giving correct path where image is saved. and i uploaded the image now i want to show that image in edit process

Sinto
  • 3,915
  • 11
  • 36
  • 70

4 Answers4

2
<img src="<?php echo $p_info['p_img']; ?>" 
alt="Product Image is not uploaded" height="700px" width="500px" />

<?php echo $p_info['p_img']; ?> should be a path which access images from the project directory not from a local path.

C:/xampp/htdocs/squadfreetry/assests/img/products_images/Acne Free (1).jpg this is wrong & will not show image.

You have to save image path starting from /assests/... and to access it by calling base_url() at first & followed by saved path in DB.

Code should be like:

<img src="<?=base_url().$p_info['p_img'];?>" 
alt="Product Image is not uploaded" height="700px" width="500px" />

Where $p_info['p_img'] is a path starting from /assests/..

Sinto
  • 3,915
  • 11
  • 36
  • 70
0

Sometimes if you view source using certain browsers (firefox, chrome), it omits the /> tag. Try view source using a notepad or something, it should display proper /> tag.

If you want a shorter tag, use this:

 <?php echo img(array('src'=>'image/picture.jpg', 'alt'=> 'alt information')); ?>

Here is detailed information: https://codeigniter.com/user_guide/helpers/html_helper.html#img

More examples:

<img src="<?php echo base_url('assets/uploads/' . $gambar)?>" alt=""/>

and

<img src='<?php echo base_url("assets/uploads/$gambar")?>' alt=""/>

Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.

Mr.Javed Multani
  • 12,549
  • 4
  • 53
  • 52
0

Please try the below way:

I am assuming that your project folder is Cart -> images/your desired image

when you do file uploading then you have to save the image in folder -> images and the image name in database.

so to access it replace your image code like this:

<img src="<?php echo base_url(); ?>images/<?php echo $p_info['p_img']; ?>" alt="Product Image is not uploaded" height="700px" width="500px" />
msz
  • 311
  • 1
  • 2
  • 16
0

On CodeIgniter 4 you can use the img function, from html helper.

  1. Adds the helper on controller -> helper('html');
  2. Generates the img tag on the view -> echo img('public/img.png').