To implement realpath(path) in php - php

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.

Related

How to use include() to include image in <img src=

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.

<img> tag is not working in php Codeigniter

<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').

Images wont show in wordpress

So,
My images are located in wp-content/themes/mytheme/images
Originally, when i converted my site from html/css the path looked like this:
<img src="images/myimage.png" alt="some text" />
That did not work and I have now tried two diffrent solutions:
<img src='<?php get_template_directory_uri(); ?>/images/myimage.png'>
and
<img src="<?php bloginfo(); ?>images/myimage.png">
Have i missed something? I am new to wordpress an php and would appreciate some help. Thanks!
You almost had it. You left off echo.
http://codex.wordpress.org/Function_Reference/get_template_directory_uri
Output the URI
<?php echo get_template_directory_uri(); ?>
The full result is:
<img src='<?php echo get_template_directory_uri(); ?>/images/myimage.png'>
I recommend you use Drupal if you haven't gotten too far with WP already. :)
Try
get_stylesheet_directory(). '/images';
/images/myimage.png">
This will return the images directory path in the currently selected theme, even if it's a child theme.
Function Reference/get stylesheet directory

php syntax in image paths parameters <img src="<?php syntax

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.

When I generate the src of an img tag, using php, it strips the forward slash at the end of the tag. Anyone come across this before?

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.

Categories