【发布时间】:2019-04-19 18:33:53
【问题描述】:
我在将 base64 编码的图像字符串传递给 python 脚本时遇到错误......无法运行 shell_execute("python hello.py $data") 这是我的代码
php 文件
<?php
echo "Good Work";
$img = file_get_contents("aaaa.jpg");
$data = base64_encode($img);
$output = shell_exec("python hello.py".$data);
echo $output;
?>
hello.py 文件
import sys
import base64
image_64_encode=sys.argv[1]
with open("image.jpg","wb") as fh:
fh.write(base64.decodebytes(image_64_encode))`
【问题讨论】:
-
你需要为你的论点留一个空间..
$output = shell_exec("python hello.py".$data);需要看起来像$output = shell_exec("python hello.py " . $data);否则 如果data='foo';它看起来像shell_exec("python hello.pyfoo"); -
另外 .. 是否在您的
php配置中启用了shell_exec?大多数安装都带有“黑名单”,需要在.ini中启用 -
扎克先生,它不起作用
-
先生,当我传递简单的字符串时,例如 $str="sohaib" 而不是 $data 然后它可以工作,但如果是图像它不起作用我不知道为什么
-
Base64 是否包含会与
arg混淆的内容,例如$或"或'等等等等等等..