2

I have and PHP app where Java coder sends me a request just with picture. Here is my code: I get php://input and write it to file as bytes

$query = file_get_contents("php://input");
$queryFile= fopen("/var/www/9292/querylog.txt","wb");
fwrite($queryFile, $query);
fclose($queryFile);

Then I remove all blanks from query. Can it cause the problem? And then I pack it in like Hexadecimal (because input that is in querylog file is hexadecimal)

$query = preg_replace('/[\s\r\n]+/', '', $query);
$queryHex=pack("H*", $query);

$inputImage=$queryHex;
$inputImage=trim($inputImage);

Also I trim it. I tried without treaming and the problem is the same.

The I write content of image to file by bytes.

$imageFile=fopen("/var/www/9292/inputPhoto.jpg", 'wb');
fwrite($imageFile, $inputImage);
fclose($imageFile);

So, the problem: When Java coder makes a request, created picture has 17 k bytes, however it has 35 k. When I take a content of querylog file and put in into post request of Advanced Rest Client, it creates readable picture with 35 k bytes. I'm completely stacked. Java coder checks file right before putting it into output streams and he says it is fine. What can cause this problem? Can Apache somehow cut query? Can you advice me, what should I check?
I came closer to solution:

Community
  • 1
  • 1
Sergey Scopin
  • 2,217
  • 9
  • 39
  • 67

0 Answers0