About PHP QR Code library (part 1) - php

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?

Related

How to pass a variable/change html from php

So I'm using PHP to grab my profile picture from my steam profile and i want to display it on the page is there any way to pass the variable containing the picture to html or edit my html code from PHP???
here is my code
<?php
$pic_path = file_get_contents("http://steamcommunity.com/id/LocalSugarDaddy");
preg_match('/<div class="playerAvatarAutoSizerInner"><img src="(.*)" \/><\/div>/i', $pic_path, $pic);
?>
I guess you are trying to use PHP variable containing image URL and want to use in html tag. If so, then you can do below:
<?php
$your_picture_str = "http://www.domainname.com/picture_url.jpg";
?>
<div><img src="<?php echo $your_picture_str; ?>" width="100%" alt="" title="" /></div>

How to add an image in codeigniter

I m learing codeigniter and i want to add an image in my view page.
I am using tag but the image is not added in the page.
So help me how i can add the image in view page of codigniter.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Blog</title>
</head>
<body>
<h2><img src="../images/logo.png"></h2>
<?php $this->load->view('blog/menu');
if ($query):foreach ($query as $post): ?>
<h4><?php echo $post->entry_name; ?> (<?php echo $post->entry_date; ?>)</h4>
<?php echo $post->entry_body; ?>
<?php endforeach;
else: ?>
<h4>No entry yet!</h4>
<?php endif; ?>
</body>
</html>
store images in an images folder at the same level as the application folder . then just link to it like this using code.
<img src="<?php echo base_url('images/logo.png'); ?>" />
Store images in an images folder at the same level as the application folder, Then just link to it like this:
<img src="../../images/image1.jpg" />
See, first you create a file with the name user_profile.php in the controller folder. no uppercase letters.
To call a View page you created in the index:
function index()
{
$this->load_controller('myView');
}
this is an example from the link i sent you that is perfect, that shows peaces of a views and how to combine them to one code from the controller.
Please go to the codeigniter website and start learning the simple stuff. or search for codeigniter via youtube. you will find a lot!
Class User_Profile extends Controller
{
function index()
{
$this->load_controller('Left_Nav');
$this->load_controller('Content_Nav');
$this->load_controller('Login_Name');
$this->load_controller('Leaderboard', 'Board');
$this->Left_Nav->index(array('highlight_selected_page' => 'blah'));
$this->load('User');
$content_data = $this->User->get_profile_details();
$this->view->load('content', $content_data);
$this->Login_Name->index();
$this->Board->index();
}
}
image in assets
<img src="<?php echo base_url(); ?>assets/images/image.png">

displaying jp2 images stored in mysql database into web page

Here 'm trying for displaying jp2 image in a web page.
But I'm not able to converting it.
The simple code is like this
<html>
<body>
<table><tr><td>
<?php
echo ' PHOT:'.getPhotoFromMysqlDB();
?>
</td></tr></table>
</body>
</html?>
getPhotoFromMysqlDB() will return jp2 image.
*If i run above example the web page displaying junk like "bytecode" *
use below code:
<html>
<body>
<table>
<tr><td>
<img src="<?php echo ' PHOT:'.getPhotoFromMysqlDB();?>">
</td></tr>
</table>
</body>
</html>

How to provide dynamic HTML in PHP?

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>

Showing a image created with the GC lib

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

Categories