Hello I have this src path in codeigniter
src="<?php echo base_url();?>photos/<?php echo $data1; echo '"/>';?>
The problem is that when i'm going to continue my code it seems that all the below code is inside an echo ""; it looks like the echo is still open.. For example i want to continue my code with a html divand thediv` is still on an echo area.. Thanks
I think you are inside of quotes of src-property.
src="<?php echo base_url();?>photos/<?php echo $data1;?>" />
try this
src="<?php echo base_url();?>photos/<?php echo $data1;?>" />
try this
<?php echo 'src="'.base_url().'photos/'.$data.'" />'; ?>
or
<?php echo '<img src="'.base_url().'photos/'.$data.'" />'; ?>
it seems like you haven't closed the last echo . tyr this
src="<?php echo base_url();?>photos/<?php echo $data1;?>" />
there is more better way of doing this in codeigniter. pass the url as the arguement to the base_url function
src="<?php echo base_url('photos/'.$data1);?>" />
try it. for more details: click
Related
Hello I'm trying to echo an image on a view page in CodeIgniter but nothing is displayed on the page.
Here I'm making the variable:
<?php $image = "<img src='../../images/stoel.jpg' alt='img' />"; ?>
And here I'm trying to echo the image:
<img src="<?php echo $image;?>">
Intro
This is the most basic php, so what's the addition of this question? Please read the basics of echo here: http://php.net/manual/en/function.echo.php (Example 1).
Learn the basics first!
Solution
1. Assign full html tag to variable and echo full html:
<?php
$image = '<img src="../../images/stoel.jpg" alt="Foo">';
echo $image;
?>
2. Or assign image path to variable and echo concat string:
<?php
$path = '../../images/stoel.jpg';
echo '<img src="' . $path . '" alt="Foo">';
?>
3. Or assign image path to variable and echo only this with php:
<?php
$path = '../../images/stoel.jpg';
?>
<img src="<?= $path; ?>" alt="Foo">
You are inserting full Image tag into src attribute.
<?php $image = "<img src='../../images/stoel.jpg' alt='img' />"; ?>
and
<?php echo $image; ?>
or
<?php $image = "../../images/stoel.jpg"; ?>
and
<img src="<?php echo $image;?>">
<?php $image = "<img src='../../images/stoel.jpg' alt='img' />"; ?>
you try like this
<?php echo $image; ?>
You are already assign full image code in variable so you just need to print your variable:
<img src="<?php echo $image;?>">
To
<?php echo $image;?>
Make sure your images out side of the application folder then you can do something like
application
images
images > stoel.jpg
system
index.php
Use Base url from the url helper
<img src="<?php echo base_url('images/stoel.jpg');?>" />
Make sure you have set the base_url in config.php
$config['base_url'] = 'http://localhost/yourproject/';
You can also use HTML Helper img();
I think this is what you mean. Since you are echoing inside the src attribute, you do not need to store the whole <image>, just the path will do.
<?php
$image = "../../images/stoel.jpg";
?>
<img src="<?php echo $image;?>">
I'm trying to show an image (or rather a link to an image) stored in a database and I'd like to get the image to show only if the link is set in the database.
Currently, if the link is not set (value is null), it shows a broken link.
Is there a way to for example use an if-statement and echo a HTML-code?
Something like this:
(The value have been fecthed to array $current in this example:)
<?php
if(isset($current['image']) {
echo "<img src='<?php echo $current['image'];
?>' class='left' style='max-height:20em; max-width:15em; margin-right:1em; margin-top:0;'})">
You used <?php twice, you have problem with quotes, brackets, etc.
<?php
if (!empty($current['image'])) {
echo "<img src='" . $current['image'] . "' class='left' style='max-height:20em; max-width:15em; margin-right:1em; margin-top:0;'>";
} else {
// here you can write for example default no-image image or whatever yo want, if you want
}
Nevermind, got it.
-Solution:
<?php if(isset($current['image'])): ?><img src="<?php echo $current['image']; ?>" class="left" style="max-height:20em; max-width:15em; margin-right:1em; margin-top:0;})">
<?php endif; ?>
<?php
if(isset($current['image'])) {
?>
<img src='<?php echo $current['image'];?>' class='left' style='max-height:20em; max-width:15em;
margin-right:1em; margin-top:0;'>
<?php
}
?>
I am trying to display an image that is in a folder "upload" by getting the image name from the database.
while($row = mysqli_fetch_array($result))
{
$pic = $row['image'];
echo $row['item'] ;
echo $row['location'];
echo $row['description'];
echo $row['forum'];
echo $row['datetime'];
echo $row['username'];
?>
</br>
<img src="upload/<?php echo $pic ?>"/>
<?php echo $row['image']; } ?>
"upload/<?php echo $pic ?>"
</body>
</html>
As you can see it display everything except the img src.
This is my database (ignore BLOB that was a test). I can't seem to figure out where I'm going wrong.
Thanks
My recommendation is to store the full relative path in the database like this:
uploads/folder/file.jpg
My preferred MySQL field type is 'varchar(255)' the your echo in te PHP code will look like:
echo '<img src="'. $row['image'].'" />';
You are trying to print the image source outside the while-loop. The while-loop will only exit when $row is empty, so $row['image'] is also empty.
1) view source (or use firebug) to see the image tag and see what is the src given there.
2) try the url: "http://{LOCAL}/projects/projectviewposted.php/upload/happyball(1).jpg" and see if you can open the image
Try this
<img src="upload/<?php echo $pic; ?>"/>
<?php echo $row['image']; } ?>
"upload/<?php echo $pic ?>"
Else note down the link of the folder path. It might be that the folder path is not correct.
Hope this helps
You can try :
while($row = mysqli_fetch_array($result))
{
$pic = $row['image'];
echo $row['item'] ;
echo $row['location'];
echo $row['description'];
echo $row['forum'];
echo $row['datetime'];
echo $row['username'];
echo '<br />
<img src="upload/'.$pic.'"/>
'.$row['image'];
}
Well after 3 days I figured it out... my header location was incorrect!
../project/projectviewposted.php/ A stupid extra slash at the end!!
Thanks for your help and suggestions!
In $ruta I have the value "imagenes/1.jpg"
If I do that, I display the image
<img src="imagenperfil/<?php echo $ruta; ?>" width="250" height="300">
but now I have this:
echo "<div class='tweet_user'><img class='user_img' src=''></div>";
So in src I would like to put
"imagenperfil/<?php echo $ruta; ?>"
I try lots of ways and none works.
thanks a lot! you always solve my all my problems
Try,
echo "<div class='tweet_user'><img class='user_img' src='imagenperfil/$ruta'/></div>" ;
Demo
$ruta = htmlspecialchars($ruta);
echo "<div class='tweet_user'><img class='user_img' src='imagenperfil/{$ruta}'></div>";
Added htmlspecialchars()
If you tried to do this:
echo "<div class='tweet_user'><img class='user_img' src='"imagenperfil/<?php echo
$ruta; ?>"'></div>";
then it won't work. You are already in php and using echo
You can try this:
echo "<div class='tweet_user'><img class='user_img' src='imagenperfil/".$ruta."'></div>";
I'm echoing quotes through htmlentities($str) and it works the first time, but it's for caption's on images that are being swapped via jQuery when clicked- then the caption shows the html entity ".
How can I echo the text with quotes so that it still appears as a " instead of the $quot; after clicked?
Here's my html
<div class="smallImageWrapper">
<?php if(empty($row_rsPTN['img1'])): echo "" ?>
<?php else: ?>
<span class="smallImage"><img src="../images/products/pbetn/50x50/<?php echo $row_rsPTN['img1']; ?>" alt="<?php echo htmlentities($row_rsPTN['img1caption']); ?>" name="smallImage" id="smallImage1" height="50px" width="50px" /></span>
<?php endif; ?>
and here's my jQuery to swap the images:
$("#smallImage1").bind("click", function() {
$("#largeimage").attr("src","../images/products/pbetn/180x280/<?php echo $row_rsPTN['img1']; ?>");
$("#largeimage").attr("alt","<?php echo htmlentities($row_rsPTN['img1caption']); ?>");
$(".caption").text("<?php echo htmlentities($row_rsPTN['img1caption']); ?>");
});
here's a link to my test site where you can see it occurring:
http://www.imsmfg.com/new/test/products/ptn.php?menuproduct=Lacing%20Strips
Let me know if you need more info.
Thanks!
Change this line:
$("#largeimage").attr("alt","<?php echo htmlentities($row_rsPTN['img1caption']); ?>");
To this:
$("#largeimage").attr("alt","<?php echo addslashes($row_rsPTN['img1caption']); ?>");
jQuery entitizes things automatically, so you don't need to put entities in that quote. You just need to escape any quotes. Hence addslashes.