Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to display an image on my website using html.
My problem is that the name of the image is saved in a php variable, so I've been trying to do the following:
<img src = <?php echo $fileName;?> >
Where &fileName is obviously the name of the file. If I simply echo this variable, it is exactly the correct file path for the operation, but the image is not displayed. Instead, on my website there's a little icon, which has nothing to do with my image. If I change it to this:
<img src = <?php $fileName;?> >
nothing at all is displayed.
I'd be grateful for any help.
You are missing the quotes:
try this:
<img src="<?php echo $fileName;?>">
Try this:
<img src="<?php echo $fileName; ?>" />
And also check what r u getting in echo $fileName; as there us need full path of image to dispay.
This is because of $fileName may have the /(slashes) which are breaking the images tag in the middle.
Instead of setting the name of the image, set its path or the full URL.
And add quotes for the src property.
Or you try Embedded code.....
<?php
echo "<img src='$filepath'/>";
//filepath is variable which contains path to the image file
?>
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
New to php and i have tried what I thought would work but it didnt work.
I have an image in my upload folder name 1002386235.png the number 1002386235 is the user id and I would like to display a profile picture of the user with the help of php. With this I can display the image. What I am trying to achieve is replace the 1002386235.png with something like $uid.png, $uid being a variable with the user id in it. I thought the following would work but it didnt
<?php
$uid = "1002386235";
?>
<img src="upload/".$uid.".png">
You need to wrap the variable $uid within php tags and since your html is not inside php tags, the concatenation dot operators are not required. Also, you need to echo the variable inside your html.
Change this line:
<img src="upload/".$uid.".png">
To this:
<img src="upload/<?php echo $uid; ?>.png">
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to add an image file to my PHP so when I echo, the picture will appear alongside the message. However I am getting a syntax error on line 3. Any help would be appreciated.
<?php
echo "President has been killed";
<IMG SRC = "D:/User Data\Documents/Sheridan/Summer Year 3/Enterprise Java Development/Projects/PhpAssignment/skull.png;"/>
?>
<?php
echo 'President has been killed
<img src="D:/User Data\Documents/Sheridan/Summer Year 3/Enterprise Java Development/Projects/PhpAssignment/skull.png;" /> ';
?>
Note the change in quotes -- single and double -- and placement of the semi-colon.
or
<?php
echo "President has been killed";
?>
<img src="D:/User Data\Documents/Sheridan/Summer Year 3/Enterprise Java Development/Projects/PhpAssignment/skull.png;" />
Move the image outside the php. Using this depends on overall markup though.
The semi-colon ends, or stops the echo statement.
Of course there's an syntax error. You are trying to output HTML inside PHP block:
Change your code to:
<?php
echo "President has been killed";
?>
<IMG SRC = "D:/User Data\Documents/Sheridan/Summer Year 3/Enterprise Java Development/Projects/PhpAssignment/skull.png;"/>
<?php
echo "President has been killed";
<IMG SRC = "D:/User Data\Documents/Sheridan/Summer Year 3/Enterprise Java Development/Projects/PhpAssignment/skull.png;"/>
?>
firstly you don't need the entire location, place the image in the folder in your root called images then place the image in there.
<?php
echo '<p>President has been killed<p><img src = "D:/User Data\Documents/Sheridan/Summer Year 3/Enterprise Java Development/Projects/PhpAssignment/skull.png"/>';
?>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I got something like this: print '<img src="'.$rlink.'">';
it shows me right link, but image doesn't appear. When I go to browser console, I get this error: http://somesite.com/somesite.com/thisimage.jpg
I tried <img src="<? php echo $rlink; ?>"/>
It is not working. I was looking around forums but didn't found a solution. Thank you for any help!
<img src="<? php echo $rlink; ?>"/>
needs to be:
<img src="<?php echo $rlink ?>">
it might not solve the problem because i dont kno what the value of the variable is. It might be wrong.
I'm guessing your variable $rlink contains somesite.com/thisimage.jpg. Since it doesn't have a protocol at the beginning, the browser thinks it's a relative path, thus trying to go to somesite.com folder, which doesn't exist. You can either put http:// at the beginning of the src, or remove domain so it's treated like the relative path it is as of now
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am trying to display an image using a variable "$images" that contains the URL parsed form an API.
This is my code:
echo "<td>""<img src='",$image,"'>""</td>\n";
I assume there is a typo I cannot detect because I get a blank screen when running this.
echo "<td>"."<img src='".$image."'>"."</td>";
Or
echo "<td><img src='".$image."'></td>";
You were missing the dots/commas after/before the td tags
use . not ,
<img src='".$image."'>
PHP requires that you chain your strings together using a .
E.g.
echo 'Test' . ' ' . 'Hello'; // Test Hello
Or simply :
echo "<td><img src='$image'></td>";
Check documentation.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
My code is random but its does not print out the picture just the text. When I add the IMAGE tag. Its go all wrong. Where do I go wrong?
$plaatje[] = 'afbeelding1.jpg';
$plaatje[] = 'afbeelding2.jpg';
$plaatje[] = 'afbeelding3.jpg';
$plaatje[] = 'afbeelding4.jpg';
$nummer2 = mt_rand(1,4);
echo "$plaatje[$nummer2]";
Use array_rand() - Picks one or more random entries out of an array
echo $plaatje[array_rand($plaatje)];
With an image tag, something like:
<img src="<?php echo $plaatje[array_rand($plaatje)]; ?>" />
or
echo "<img src='".$plaatje[array_rand($plaatje)]."' />";
Here is the documentation
Although you should add the image tag to show where it goes wrong, your code already has a problem as array indices are 0-based.
So you would need:
$nummer2 = mt_rand(0,3);