将二进制数据传递给PHP system()命令 [英] Pass binary data into PHP system() command
本文介绍了将二进制数据传递给PHP system()命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将二进制数据输入 system()
,如下所示?
Is it possible to hand binary data into system()
like below?
$contents = file_get_contents("http://somesite.com/image.jpg");
$out = system("{$contents} | convert - -fuzz 10% -trim jpeg:-");
当我进入终端并执行 cat filename |转换 - -fuzz 10%-trim jpeg: -
它将二进制数据返回给STDOUT ...但是当我 echo()
或<$ c时$ c> print_r()上面的数据,它总是空的。
When I go into the terminal and execute cat filename | convert - -fuzz 10% -trim jpeg:-
it returns binary data to STDOUT... but when I echo()
or print_r()
the data above, it's always empty.
推荐答案
-
使用base64:
Use base64:
system('echo ' . base64_encode($contents) . " | base64 -d | convert - -fuzz 10% -trim jpeg:-");
你可能会问一个单独的问题
You probably ask a separated question for that
这篇关于将二进制数据传递给PHP system()命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文