In C# (ASP.NET MVC) I have method which opens one file and put all the file content into the byte array like this:
byte[] bytes = File.ReadAllBytes(filename);
On PHP side I have PHP Slim Framework API method which is called from C# and I do a POST JSON object that contains this file byte array -> it has these properties:
- myObjectId - int - id of my object
- filename - string - file name
- fileBytes - array - byte array of this file
You can get the demo of this JSON content here: https://justpaste.it/1d8jq
On PHP side I do json_decode of what I received like this:
$fileObject = json_decode($app->request->getBody());
And I get the same array of bytes in member:
$fileBytes = $fileObject->fileBytes;
The question now is how I can save this byte array into the Word file (it is a Word file). I used this method and it saves but it is some very strange content/strange symbols inside (not the original content)...
$binStr = '';
foreach ($fileBytes as $fileByte)
{
$binStr .= pack('i', $fileByte);
}
$binStr .= "\n";
$fileTemp = '/tmp/'.$filename;
file_put_contents($fileTemp, $binStr);
So, how I can properly save these bytes (this byte array has the same elements/integers in PHP like in C# - looks like it is correctly sent))?
If this matters, C# part is on Windows Server and PHP is on Linux/CentOS server.