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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

steelseth12Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.