Page 1 of 1

Display file in browser

Posted: Wed Aug 06, 2003 10:42 am
by daven
I am trying to display files in a browser. For example, a php file will merely have the code printed to the browser, rather than interpreted. However, PHP files always are misssing have the line with the initial '<?', and I am having trouble displaying images.
I have also tried using fpassthru, but it will not interpret images at all.

Code: Select all

<?
$dir="/path/on/server/";
$name="filename.ext";
chdir($dir);
header("Content-disposition: inline; filename=$name");
header("Content-type: $mimetype"); # If I comment out this line, text files are interpreted (displayed) correctly, aside from the opening <? line.  However, images are not.

$arr=file($name);
$sca=implode("",$arr);
echo nl2br($sca);
?>

Posted: Wed Aug 06, 2003 6:22 pm
by Galahad
Read this thread. My sample code give a pretty good example of what you could do. I had an error in that code The cache-control shouldn't have been public, read through the thread to see some other options. Although, my purpose was to restrict access to files, so maybe public would work for you.

Oh, I just noticed that you replied to that thread... Have you tried the headers I used? When I give it a correct content-type (such as "image/jpeg") it opens in the browser. I'm not sure this is too helpful, but you might get some ideas to try.