Equivalent readfile for binary data?

I am using http://undesigned.org.za/2007/10/22/amazon-s3-php-class/documentation to access private files using php. I can get the file data by specifying $ object-> body. I really want to see the image in the browser or play the video in the video player. Is there any way to do this?

I think I need something like readfile. The problem is in the readfile - I need the file path. The path is closed, so I can not use it. Is there a way to make readfile binary data?

I put this in php thinking it would help, but it still displays binary data.

header('Content: image/jpeg'); header('Content-Disposition: inline; filename=IMAG0108.jpg'); echo $object->body; 
+4
source share
2 answers

You simply set the header for the content type and output the reading file to the browser. What I am doing is creating a new php file, for example "showimage.php", which accepts an identifier or some so that I know which image to display. Then I use it on the browser page :.

In showimage.php something like:

 <?php header('Content-type: image/png'); readfile('/var/images/' . $_GET['id'] . '.png'); // or // echo $object->body; ?> 

This will read the file from the local system and output it as an image. On top of my head so I can ruin this code!

+1
source
 header('Content: image/jpeg'); echo $object->body; 

Should work fine (for JPEG), you need to know what type of file is in question, and then send the appropriate content headers.

0
source

All Articles