view image file

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
drfeelgood
Forum Newbie
Posts: 15
Joined: Mon Sep 01, 2008 9:57 pm

view image file

Post by drfeelgood »

Hi all,

I want to view image file and save it to variable. it shows nothing in browser.
here is my code :

<?php

$files = "filename.gif";
echo exec('vi $files');

?>
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: view image file

Post by Syntac »

Code: Select all

echo file_get_contents( "filename.gif" );
However, this won't work, because it'll be echoed as text.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: view image file

Post by alex.barylski »

I think it depends on the browser...

IE is pretty good usually at automgaically handling MIME types from the file source itself. FireFox and other more compliant browsers might actually you require to set some headers first...

Look up header() on PHP web site I'm sure there are examples of how this is done.

Cheers,
Alex
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: view image file

Post by pcoder »

Try this:

Code: Select all

 
header('Content-Type: image/jpeg');
$files = file_get_contents("filename.jpeg");
echo $files;
 
It works 8)
Post Reply