Can't display the image in browser - php

$images['result'][0]['image_path'] - here I have path of image. It is in public folder.
<img width="150" height="150" alt="150x150" src="<?php BASEPATH."../public/" echo $images['result'][0]['image_path'];?>" />
Can anyone help me to display this image?

Try This,
<img width="150" height="150" alt="150x150" src="<?php echo base_url('your/Folder/Structure/').$images['result'][0]['image_path'];?>" />
First concate your file name with path which causing the issue.
base_url() will also help you to fetch/show your image

Related

Assign Image SRC in php

After retrieve image path from database I want to pass it to <img> tag to show up,
I read this solution, but I do not want to echo it, I want to assign it as src for image tag
I tried this:
$image = mysqli_fetch_array($user_images);
$img1 = $image['file_path'];
$imageData = base64_encode(file_get_contents($img1));
$src = 'data: '.mime_content_type($img1).';base64,'.$imageData;
How can I assign $src to image, I tried this but no luck :(
<img id="img1" width="150" height="150" src="' . $src . '"/>
Thanks in advance.
Inside the HTML you still need to echo the value of $src. This should work:
<img id="img1" width="150" height="150" src="<?php echo $src; ?>"/>
Try with PHP tags like below:-
<img id="img1" width="150" height="150" src="<?php echo $src;?>"/>
Reasonable solution I can think of is
<img id="img1" width="150" height="150" src="<?php echo $src; ?>"/>
but the code where you get the image source has to be above the image tag, so you have the $src.
You are using PHP language and in Php, you can't pass variable directly in the Tag you have to set a variable in the PHP environment.
To create Php environment you can right <?php ?> or you can use to echo variable <?= ?> between these PHP tags you can pas your variables to echo and assign or anything else what you want to do.
<img id="img1" width="150" height="150" src="<?= $src ?>"/>

Error 403 Image not found in Drupal 7

I create a block from configuration. Inside this block, I write this code...
<div class="provider-bg" id="provider1">
<img alt="" class="img-responsive" src="<?php echo base_path().path_to_theme() ?>/images/provider-1.jpg" />
</div>
Then, I save with PHP in text format.
My virtual host is ... http://localhost:8888/drupal
So, the image path will be like this ...
<img alt="" src="/drupal/sites/all/themes/myancast/images/ios.png">
This image appears in the last few days ago. Today, I run the site and that image disappear immediately and got 403 error.
Failed to load resource: the server responded with a status of 403 (Forbidden).
I'm trying to find the solution the whole day. But, I still cannot solve.
Can anyone help me please ?
Add global $base_url in your code and use like below
<img alt="" class="img-responsive" src="<?php echo $base_url.'/'.path_to_theme(); ?>/images/provider-1.jpg" />
did you try this ?
<img alt="" class="img-responsive" src="<?php echo '/'.path_to_theme(); ?>/images/provider-1.jpg" />
try this,
<?php
$imgurl = file_create_url(path_to_theme().'/images/provider-1.jpg');
?>
<img alt="" class="img-responsive" src="<?php echo $imgurl ?>"/>

I want to give green and red color for image areas

I want to show status with 0 area as red dot and status with 1 area are green. I used style tag for area. But not color coming on image area. Anybody knows please help me. I am sharing my code below
<html>
<map name="map1" id="_map1">
<?php
foreach ($points as $point)
{
$name=$point->name;
$status=$point->status;
if($status==1){ ?>
<area shape="rect" coords="10,15,18,20" href="<?php echo base_url()?>assets/images/green.jpg" alt="" title="" onmouseover="<?php echo $name; ?>" />
<?php
}
else if($status==0) {?>
<area shape="rect" coords="0,0,50,50" href="<?php echo base_url()?>assets/images/red.jpg" alt="" title="" onmouseover="<?php echo $name; ?>"/>
<?php
}
} ?>
</map>
<img id="map1" src="<?php echo base_url()?>assets/images/rectangle.png" usemap="#map1" border="0" width="800" height="600" alt="" />
</html>
See the example use of <map> Html map tag
The href attribute does not show the image (red or green). It is a hyperlink to the target image. The image displays on the screen is the src file of the <img> tag.
You may need to generate the image dynamically on the server side, or use <canvas> to render the data on the client side.

Can't load image

As you can see, there is no image. What's wrong with this?
$displayProdCat .= '<div class="product">
<img src="Customer/images/product'.$ItemNo.'.jpg" width="170" height="150" />
<h3>'.$ItemName.'</h3>
<p class="product_price">Php '.$Price.'</p>
Add to Cart</div>';
Probably a wrong image url is specified. Look at the source.

Using a $_GET variable as img src

I am trying to link an image using the same name as a $_GET variable, example bellow:
The $_GET
$venue = $_GET['venue'];
Is it possible to use '$venue' as the image src example being something like
<div id="imgbox">
<img src="$venue.jpg" alt="venueimage" height="150" width="250">
</div>
My attempts so far have been unsuccessful, is it possible in a similar way to this or is there an alterantive?
Thankyou
You forgot your PHP tags and echo statement:
<div id="imgbox">
<img src="<?php echo $venue; ?>.jpg" alt="venueimage" height="150" width="250">
</div>
or shorthand:
<div id="imgbox">
<img src="<?= $venue; ?>.jpg" alt="venueimage" height="150" width="250">
</div>
As pointed out by Quentin we should take this a step further and sanitize our output:
<div id="imgbox">
<img src="<?= htmlspecialchars($venue); ?>.jpg" alt="venueimage" height="150" width="250">
</div>
You should be able to use <img src="<?php echo $venue; ?>.jpg" alt="venueimage" height="150" width="250">
I forgot to sanitize the code as well. You would need to add:
<img src="<?php echo htmlspecialchars($venue); ?>.jpg" alt="venuimage" height="150" width="250">

Categories