views:

112

answers:

1

I want to send files through php using readfile()

What i've noticed is that readfile forces a download, but what if i want to show an image in the browser and not force a download?

Would readfile still force download even if the file is an image?

If it does, is there a solution so i can use tags with it when the file is an image?

Thanks!

+2  A: 

You need to set the MIME type with the header() function. There should be info in the comments. Something like:

<?php
header('Content-type: image/png'); 
?>
Pestilence
as in, instead of octect/stream , set it to octect/image? (i dont know the correct terms for it as you can probably tell :P)
jiexi
octet/anything will force a download, IIRC. If you don't want it to, then you need to set the type appropriately. The GD documentation shows how to do this pretty well, when you're generating images server-side. The basic idea is the same.
Pestilence
is there a php function that automatically finds the correct mime type?
jiexi
Yes... there's Fileinfo, which I've never used before. It looks like it replaces the old way (that I have used) and even tries to read the file, instead of just looking at the extension: http://www.php.net/manual/en/book.fileinfo.php
Pestilence