Error 403 Image not found in Drupal 7 - php

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 ?>"/>

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 ?>"/>

Can't display the image in browser

$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

Image file is not being located

Hi , I have placed in my php to get the image file from the folder, but it is giving me a error in the source saying
Warning: Division by zero in
My code is :
<img src="<?php echo get_bloginfo('template_directory') /imgs/Logo.png;?>" alt="Logo" class="logo">
It was working for me last week , i forget what I have changed but now can not fix this , can anyone please help?
<img src="<?php echo get_bloginfo('template_directory').'/imgs/Logo.png';?>" alt="Logo" class="logo">
Try this
<img src="<?php echo get_bloginfo('template_directory');?>/imgs/Logo.png" alt="Logo" class="logo">

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.

Linking image to outside url in WordPress Template

I've encountered this issue a couple times but have always found a "hack" way around it. Is there a special way to link an image in a WordPress template to an outside url beyond the typical a href tag? Here's the images I'm trying to link to outside urls:
<div class="socialMedia">
Follow Us: <br />
<img src="<?php echo get_bloginfo('template_url') ?>/images/facebook.png" alt="facebook"/>
<img src="<?php echo get_bloginfo('template_url') ?>/images/twitter.png" alt="twitter"/>
<img src="<?php echo get_bloginfo('template_url') ?>/images/googleplus.png" alt="google plus"/>
<img src="<?php echo get_bloginfo('template_url') ?>/images/instagram.png" alt="instagram"/>
</div><!--.socialMedia-->
<div class="socialMedia">
Follow Us: <br />
<a href="<?php echo get_bloginfo('template_url') ?>/images/facebook.png" target="_blank" > <img src="<?php echo get_bloginfo('template_url') ?>/images/facebook.png" alt="facebook"/> </a>
</div><!--.socialMedia-->
did you mean it!!?

Categories