I have a dynamic image as PHP
file:
<?php
header('Content-type: image/png');
echo file_get_contents('image.png');
Now I want to read content image and store it into a file with PHP
and CURL
and executable commands.
First for sure, I test this command in cmd:
# curl -s http://localhost/image.php > output.png
This works good.
Now I use of same command in the php code with shell_exec
function:
<?php
$cmd = 'curl -s http://localhost/image.php';
$out = shell_exec($cmd);
file_put_contents('output.png', $out);
But the output incomplete:
‰PNG
And this may be binary in the photo because of NULL characters.
Another test I try with exec
function.
<?php
$cmd = 'curl -s http://localhost/image.php';
exec($cmd, $out);
file_put_contents('output.png', $out);
Seem the output file contain real binary image:
‰PNG
IHDR ً P Z'ï PLTEےےے –––¹¸vٍ pHYs ؤ ؤ•+ tIDATX…¥کQ®©„Mdٍl"ْ®"کgˆ`ض“Hة{"e61«¼_u–0™(sخك
کr¹\يكےًا~¶’¼ïk¥‘’¥½ZKأb¬Zkّ‰¶»¯½|إj–|ظ.nضـ²¯آ‡y*üµàٌب›g–Z²'¹چضِê¶طج£µث5³kjںىkoُ
But the image will not be shown.
I diff real image and new generated image:
Apparently, because the content of the $out
is an array. Not well written in the new file.
Now, Where are my forms of work and how can I get to my goal?
EDIT: seem this problem is just on windows.