Post binary file return

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Oct 17, 2018 11:56 am

Wed Oct 17, 2018 12:11 pm

Hi, I have a problem. I am returning a binary file from the server (post call) but when I receive the file, it is smaller. In the sending of the message certain bytes are deleted. I use this code:

Code: Select all


   $filename = 'image.ppm';
   $path = '/var/www/'.$filename;
   header('Content-Type: application/octet-stream');
   header('Content-Length: ' . filesize($path));
   header('Content-Disposition: attachment; filename=' . $filename);
   header("Pragma: public");
   header("Expires: 0");
   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
   header("Cache-Control: public", false);
   header("Content-Description: File Transfer");
   header("Accept-Ranges: bytes");
   header("Content-Transfer-Encoding: binary");
   ob_clean();   // discard any data in the output buffer (if possible)
   flush();      // flush headers
I suppose that in this way the file is sent in binary and there should be no problem with special characters. But the file size is different on the server and on the client. I would appreciate if someone can help me.

Thank you.

Post Reply