exec('7za.exe e -so ...') 的输出有问题

问题描述 投票:0回答:1

感觉有些数据在某处被切断了:

@exec('7za.exe" e -so "archive.zip" "img.jpg"', $out);

$out - 是 bin 数据的数组 $data = implode( "" , $out ); imagecreatefromstring($data); // 不工作

如果添加“ “ 内爆(): $数据=内爆(“ “,$out); imagecreatefromstring($data); // 创建一个扭曲的图像。 enter image description here

文件是正确的,用其他函数读取也正常,但我需要使用本地的7za.exe,而不是内置函数。

php exec
1个回答
0
投票

exec()
仅适用于输出文本的程序。这里你想要获取二进制内容,所以你应该使用
passthru()
来代替。

要捕获结果,您需要使用输出缓冲:

ob_start();
passthru('7za.exe ...');
$data = ob_get_clean();
$im = imagecreatefromstring($data);
© www.soinside.com 2019 - 2024. All rights reserved.