i have my test.php:
<?php
echo "Image:<br/>";
include('draw.php');
?>
and my draw.php:
<?php
$img = imagecreate(250,80);
...
header("Content-type: image/jpeg"); imagejpeg($img); imagedestroy($img);
?>
now, visiting test.php tells me that headers is already sent. How do i show the image in draw.php "realtime" (not by saving to server and loading it using img tag)?
?>
If you want to incorporate this into an html page, change test.php to this:
<?php
echo "Image:<br/>";
echo '<img src="draw.php" />'
?>
You could just as easily make it a static html page:
<html>
<head>
<title>Test</title>
</head>
<body>
Images: <br />
<img src="draw.php" />
</body>
</html>
Remove echo "Image:<br/>"; from test.php and read carefully about HTTP headers http://php.net/manual/en/function.header.php so that you don't make the same mistake again
Related
Can't get image URL to display in my code; this is my URL: https://production.cdmycdn.com/webpack/renderer/d7285ffbbd0ca6d1d2179f7d22ea1f67.svg
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<!DOCTYPE html>
<html>
<head>
<title>PHP Exercise 1: Links and Variables</title>
</head>
<body>
<h1>PHP Exercise 1: Links and Variables</h1>
<p>Use PHP echo and variables to output the
following link information:</p>
<hr>
<?php
$linkName ='<h1> Codecademy <h1>';
$linkURL = 'codecademy';
$linkImage =
'https://production.cdmycdn.com/webpack/renderer/d7285ffbbd0ca6d1d2179f7d22ea1f67.svg';
$linkDescription = 'Learn to code interactively, for free.';
$my_name = "peter";
echo "<img>" . $linkImage . "</img>";
echo $linkName;
echo "<br>";
echo $linkURL;
echo "<br>";
echo $linkImage;
echo "<br>";
echo $linkDescription;
$linkImage = 'https://production.cdmycdn.com/webpack/renderer/d7285ffbbd0ca6d1d2179f7d22ea1f67.svg';
echo '<img src="data:image/jpeg;base64,">';
?>
</body>
</html>
A link to an image should always be put in the src attribute when you're using the img tag in html.
That means you should be looking for something like "<img src=".$linkImage."></img>" instead of "<img>".$linkImage."</img>"
Of course, that only applies if the problem you're referring to is the fact that there should be an image after the sentence "Learn to code interactively, for free."
Works just fine for me. Try checking php permissions.
I am using PHP QR Code library.
Below are my code:
testqr.php
<?php
include('phpqrcode/qrlib.php');
?>
<html>
<body>
<?php
$studentno = 123456;
$image = $studentno.'.png';
QRcode::png($studentno, $image);
?>
<img src="<?php echo $image; ?>" />
</body>
</html>
From the above code, it will display a qr code on the web page and save an image file.
My question is can I just display a qr code on the web page without save an image file?
I'm using this line of php in my main page
echo generateRadioButtons("fbresponse.php", "moRating1", 6);
Which when posting the following on the response file
echo $_POST['moRating1']
It works fine and displays the correct result, but! my question is how would i add text to that so..
Blah blah blah, you rated x question: 'moRating1'
I've tried doing
<html>
<head>
<title>Questions</title>
</head>
<body>
<h1>Survey responses</h1>
<p>How well did you rate it : <?php print $moRating1 ?></p>
</body>
</html>
inside the response file but that just doesnt load anything..
Any help please!
It's probably because this function uses eval() to execute its content (I guess it from lack of PHP tags in your first example).
If it's true, then you should be able to close PHP tag, print HTML and open it again.
?>
<html>
<head>
<title>Questions</title>
</head>
<body>
<h1>Survey responses</h1>
<p>How well did you rate it : <?php print $_POST['moRating1'] ?></p>
</body>
</html>
try doing:
$mRating1 = $_POST['moRating1'];
...
?>
...
<p>How well did you rate it: <?php echo $mRating1?></p>
I've got a HTML file which I've created and is stored in a directory elsewhere.
The problem is, I'd like to be able to get content externally and place it within the HTML file.
I figured I could use PHP for this, because it's server-side and can access the files I want.
So, I created a PHP script which opens and echoes a HTML file, and afterwards, echos some JavaScript to change elements that are on the screen.
Here's my PHP file:
<?php
$html = file_get_contents('file.html');
$imageurl = file_get_contents('url.txt');
$js = '<script type=\'text/javascript\'>updateImage(\'img1\', '.$imageurl.');</script>';
echo $html;
echo $js;
?>
..and the HTML file:
<html>
<script type="text/javascript">
function updateImage(id, url) {
var img = document.getElementsByName(id)[0];
img.src = url;
}
</script>
<body>
<img src="" name="img1" />
</body>
</html>
It's not the best method, but it works.
I would like to know a way to do this within PHP, not using JavaScript.
I'm not sure as of the best approach to this.
You could use include and ob_get_contents to get the html as string and do some str_replace or preg_replace on that.
Your HTML:
<html>
<body>
<img src="{IMAGE_SRC}" width="512" height="512" name="image" />
</body>
</html>
Your PHP:
ob_start();
include 'your_file.html';
$buffer = ob_get_contents();
ob_end_clean();
$buffer = str_replace('{IMAGE_SRC}', 'your_image.png', $buffer);
print $buffer;
That is a pretty basic question. You should read some PHP and HTML Tutorials. Something like this will do the trick:
<html>
<body>
<img src="" width="512" height="512" name="<?= $somePhpVariableContainingTheName ?>" />
</body>
</html>
i have this code trying to print an image in an html using
session variable from a php.Here is my code:
</head>
<body>
<?php
session_id(1);
session_start();
echo $_SESSION['phname'];
?>
<img src="../uploads/$_SESSION['phname']" alt="photo" width="498" height="720" border="0" />
here:
session_id(1);
session_start();
echo $_SESSION['phname'];
i'm checking if my variable has passed
from the php and its ok.
and here
?>
<img src="../uploads/$_SESSION['phname']" alt="photo" width="498" height="720" border="0" />
i'm using php to print the image from the following source
src="../uploads/$_SESSION['phname']"
when $_SESSION['phname'] is my image's name but i'm not getting the image. Is there something wrong with my code or
is there any other way to print my image?
i try a lot of things and a lot of codes
i found on the net but nothing help me more.
You need to do your session_start before you output anything to the browser as it sends some headers.
And of course when you want to echo something in php, you need php tags and an echo statement...
<?session_start();?>
</head>
<body>
<?php
session_id(1);
echo $_SESSION['phname'];
echo "<img src=\"../uploads/". $_SESSION['phname']."\" alt=\"photo\" width=\"498\" height="720" border="0" />";
?>