开发者

fread showing binary data not the actual image

Basically I am doing a fread of a file and it is dumping out the raw data in my browser rather than showing me the actual image.

Googling around it appears I need to add header values before I call the function. I have tried that but still the data is being shown on screen rather than showing the actual image.

I have used readfile_chunked function in the past to help display video in a video player so I was hoping to use that function again to display other filetypes (images, txt,etc). Here is the readfile_chunked function.

function readfile_chunked($filename,$retbytes=true) {
   $chunksize = 1*(1024*1024); // how many bytes per chunk
   $buffer = '';
   $cnt =0;
   // $handle = fopen($filename, 'rb');
   $handle = fopen($filename, 'rb');
   if ($handle === false) {
       return false;
   }
   while (!feof($handle)) {
       $buffer = fread($handle, $chunksize);
       echo $buffer;开发者_如何学JAVA
       ob_flush();
       flush();
       if ($retbytes) {
           $cnt += strlen($buffer);
       }
   }
       $status = fclose($handle);
   if ($retbytes && $status) {
       return $cnt; // return num. bytes delivered like readfile() does.
   }
   return $status;

}

This is what I'm doing...doing the header stuff then I call the function....

header("Content-type: $type");
header("Content-Length: $size");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: inline; filename=$uri");
header("Pragma: no-cache");
header("Expires: 0");


readfile_chunked($filename);

I have tried changing the content-disposition to inline or attachement but it doesn't display inline and it doesn't download for attachment either.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜