Page 1 of 1

view image file

Posted: Thu Nov 06, 2008 9:10 pm
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');

?>

Re: view image file

Posted: Thu Nov 06, 2008 9:31 pm
by Syntac

Code: Select all

echo file_get_contents( "filename.gif" );
However, this won't work, because it'll be echoed as text.

Re: view image file

Posted: Fri Nov 07, 2008 2:11 am
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

Re: view image file

Posted: Fri Nov 07, 2008 2:44 am
by pcoder
Try this:

Code: Select all

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