Image display using php script for img src

I am tearing hair out.... I wish to use a php file to display an image.  Now thats a pretty simple exercise I understand - using the php file as the src element of a img call.

Like: <img src="makeimage.php"> etc

I have a pretty simplified example which i know is generating the path to the file and the file correctly - but simply will not play ball and states "errors in file" when viewed in firefox..

Perhaps an expert could comment on this code?

Server is Apache / Php 5 running on Intel Mac via MAMP Pro

//for the sake of ease i am making some variables hardcoded
//allthough in my script they arrive in another fashion
 
$path = "chat_images/";
$src = "chat1_online";
$type = "gif";
 
$img = $path.$src.".".$type;
 
//reveals: chat_images/chat1_online.gif
//which does exist on the server 
       
header("Content-type: image/{$type}");
 
//attempt one (these not done at same time obviously)
imagegif($img);
exit();
 
//attempt two
echo $img;
exit();
 
//attempt three
print $img;
exit();
 
//none work...

Open in new window

cooperholtAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
steelseth12Connect With a Mentor Commented:
imagegif expects an image resource.

see http://www.php.net/manual/en/function.imagecreatefromgif.php
<?
 
//for the sake of ease i am making some variables hardcoded
//allthough in my script they arrive in another fashion
 
$path = "chat_images/";
$src = "chat1_online";
$type = "gif";
 
$img = $path.$src.".".$type;
 
//reveals: chat_images/chat1_online.gif
//which does exist on the server 
       
header("Content-type: image/{$type}");
 
$resource = imagecreatefromgif($img); 
 
//attempt one (these not done at same time obviously)
imagegif($resource);
exit();
 

Open in new window

0
 
cooperholtAuthor Commented:
Yeah, thats what the script said, so I tinkered a bit - the only reason for leaving it in as one of the example endings of the script was to demonstrate that i had attempted differring things :)

Apparently though, the last 2 echo and print statements (when used individually of course) still dont provide anything..

I am starting to wonder if this is a server specific issue.....
0
 
cooperholtAuthor Commented:
Dang!!!!!

I just realised you placed a link there at the top...  which fixed it....

Cheers a lot!!

Oo
0
All Courses

From novice to tech pro — start learning today.