Background: using zurb foundation's data-interchange, running in Concrete5.
Using php inside an img src path is easy enough.
<img src="<?php echo $this->getThemePath(); ?>/images/myImage.png" \>
But when I go further, passing parameters and such to use data-interchange, things get messy. I know it probably has something to do with quotes or parentheses and such. Help with this code?
<img src="<?php echo $this->getThemePath(); ?>/images/myImage.png" data-interchange="[<?php echo $this->getThemePath(); ?>/images/myImage.png, (default)], [<?php echo $this->getThemePath(); ?>/images/myImage_#2x.png, (retina)]">
Try removing src="<?php echo $this->getThemePath(); ?>/images/myImage.png". It shouldn't be necessary since you have that file specified as the default in the data-interchange parameter.
Related
I need help with HTML and PHP. How I can use include() in <img src""> ?
Example:
<?php
some code here
$page_banner = $_SERVER['DOCUMENT_ROOT'].'/img/page-banner.png';
some code here
?>
some code here
<img src=<?php include($page_banner); ?>>
But unfortunately it doesn't work. I hope you understand what I'm trying to say.
Sorry for bad english. Google helps me.
you dont need\want include here its simply.
<img src='<?php echo $page_banner; ?>'>
src= is the URI to the image
You can use include() for files, not for variables. So just use the variable without include().
<img src='<?php echo $page_banner; ?>'>
Don't forget the quotes around the image path.
i just started learning Php, right now im trying to convert a HTML page to a Wordpress Theme. I have trouble trying to display images...
In my HTML page i have imgs like:
<img class="mainlogoclean" src="images/akbarlogoclean.png"/>
When i tried to change it with php my page just stop working:
<img class="mainlogoclean" src="<?php echo /images/akbarlogoclean.png ?>"/>
You will have to echo a string for it to work properly.
i.e. have /images/akbarlogoclean.png inside single/double quotes.
You can learn more about how echo works Here
The code could be written in following ways
<img class="mainlogoclean" src="<?php echo "/images/akbarlogoclean.png" ?>"/>
Or you could also try the shorthand version of using echo
<img class="mainlogoclean" src="<?="/images/akbarlogoclean.png" ?>"/>
Both of these give the following output
<img class="mainlogoclean" src="/images/akbarlogoclean.png"/>
<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
<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/..
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.
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" />
On CodeIgniter 4 you can use the img function, from html helper.
Adds the helper on controller -> helper('html');
Generates the img tag on the view -> echo img('public/img.png').
Is that possible to implement php function realpath(path) for the below code?
<img class="img-responsive" src="assets/images/home.jpg">
I am trying this:
<?php $homepath = realpath ("assets/images/home.jpg"); ?>
<img class="img-responsive" src="<?php echo $homepath ?>">
but the image doesn't show.
realpath() returns the path to a file on your server's hard disk. This is likely to be something along the lines of:
/home/yourusername/public_html/assets/images/home.jpg
Putting this path in an HTML tag will not work. Don't do it.
If I have the path to an image stored in $thumbPath and I put that as the img tag's src it strips the end "/" from the tag. Does anyone have any ideas about this?
<img src="<?php echo $thumbPath; ?>" />
// <img src="path/to/file/foo.jpg">
Thanks
It seems very unlikely that this is the location of the problem. "echo" is not semantically aware. It's much more likely that the error exists in whatever code is generating $thumbPath.
Here's a test to show that Wrikken et al. are correct:
<?php
ob_start();
$thumbPath = 'path/to/file/foo.jpg';
?>
<img src="<?php echo $thumbPath; ?>" />
<?php
echo htmlspecialchars(ob_get_clean());
// Output:
// Browser: <img src="path/to/file/foo.jpg" />
// CLI: <img src="path/to/file/foo.jpg" />
It will not strip it. As the / is outside the scope of the code you have provided us with. The source of the problem is something else, without any more info I can't help you.