0

I have an PHP Yii2 webapplication, which runs an command line script using passthru(). The passthru() result should passed into an downloaded file, so that the user can download the output of passthru().

Example:

If I execute the following command line:

$ /bin/cat /PATH/pic.jpg > output.jpg

...I get an file output.jpg, which is identical to pic.jpg (same md5 checksum)

But I need to execute this mechanism in an web application:

If I doing the same using passthru() in order to send the file to the users browser:

            header("Cache-Control: private");
            header("Content-Type: application/octet-stream");
            header("Content-Disposition: attachment; filename=download.jpg");
            passthru ('/bin/cat /PATH/pic.jpg');

....than I get an download.jpg which is not the same like pic.jpg I this example-case download.jpg is 1126 bytes smaller (picture size is around 13MBytes) and the picture can not be opend in some picture viewer.

The Bndr
  • 13,204
  • 16
  • 68
  • 107
  • Is there any reason why you're not using `readfile()` here? – rob006 Nov 14 '18 at 15:35
  • 1
    @rob006 This is only an example to simplify/show the problem. In "reallife" `pic.jpg` does not exist an `passthru()` is calling an executable, which generates the binary stuff, which should be send to the user, which see the download in the browser. – The Bndr Nov 15 '18 at 12:08

0 Answers0