OTA Problem with PHP script HTTP_UPDATE_FAILED Error (-106): Verify Bin Header Failed

i have a problem with the OTA Update.
If i use the http link of the update file
_httpUpdate_return ret = ESPhttpUpdate.update(client, "http://iot.mynet.lan/bin/D1Mini_1Stripe_Movement_Sensor_Display_LightSensor_Bed.ino.bin.signed"); - everything works perfect - the update is done.

If i use a php script,
t_httpUpdate_return ret = ESPhttpUpdate.update(client, "http://iot.mynet.lan/checkArduinoUpdate.php");
it fails with:

[httpUpdate] Header read fin.
[httpUpdate] Server header:
[httpUpdate] - code: 200
[httpUpdate] - len: 396580
[httpUpdate] - MD5: 92aef8810a7451f80c6c599107b413f4
[httpUpdate] ESP8266 info:
[httpUpdate] - free Space: 1699840
[httpUpdate] - current Sketch Size: 396320
[httpUpdate] runUpdate flash...
[httpUpdate] Magic header does not start with 0xE9
HTTP_UPDATE_FAILED Error (-106): Verify Bin Header Failed

I have validated the (php) returned file on my computer - it starts with 0xE9.

Here is the relevant php code: (copied from the supplied example)

function sendFile($path) {

    header($_SERVER["SERVER_PROTOCOL"].' 200 OK', true, 200);
    header('Content-Type: application/octet-stream', true);
    header('Content-Disposition: attachment; filename='.basename($path));
    header('Content-Length: '.filesize($path), true);
    header('x-MD5: '.md5_file($path), true);

It seems, that the somehow the return of the update file is different between php and direct url link, although the browser downloaded file also starts with 0xE9.

best regards


A further investigation showed, that the php download has an extra byte (0x31) at position 1 and 0xE9 at position 2 (what should be at 1)

There for at the end the last byte is missing.