Having trouble passing php as img

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
inkexit
Forum Newbie
Posts: 4
Joined: Mon Jul 05, 2010 7:36 pm

Having trouble passing php as img

Post by inkexit »

Code: Select all

<?php    
header('Content-type: image/jpeg');
error_reporting(E_ALL);   
ini_set('display_errors', True);     
$data = file_get_contents("test.txt");    
if(is_numeric($data))  
{  
	echo '<img src="'.$data.'.jpg" />';   
}  
?>  
I placed this in an html file inbetween the <body> tags.

The data this script gets is just 1 integer saved in test.txt. I have uploaded various images like 1.jpg and 2.jpg to the directory.

It should be working, but all I get is " '; } ?>"

I gather there is a better way to do this? inside html img tags? something more like this:

<img src="/GetData.php?filename=<?PHP $data; ?>.jpg" />

I just don't understand the syntax of using PHP this way.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Having trouble passing php as img

Post by requinix »

You have more problems than just with the syntax.

Code: Select all

<?php

header("Content-Type: image/jpeg");
$number = (int)file_get_contents("test.txt"); // image number
readfile($number . ".jpg");

?>
Post Reply