如何通过shell保存二进制内容?
我写的示例不起作用
$f = file_get_contents("my.exe");
exec("echo $f > new.exe");
最佳答案
好吧,也许将来有人会想要这个待办事项,带有 nobody/www-data 的 php 可以写入根文件
function my_file_put_contents($f, $content){
$rand_file = "/tmp/my_tmp_".uniqid('', true);
file_put_contents($rand_file, $content);
exec('sudo cp '.escapeshellarg($rand_file).' '.escapeshellarg($f).' && rm '.escapeshellarg($rand_file));
}
然后使用 visudo 编辑/etc/sudoers
www-data ALL = (ALL) NOPASSWD: /bin/rm
www-data ALL = (ALL) NOPASSWD: /bin/cp
关于php - 通过 php 读取二进制文件并通过 shell 上的 exec 保存它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48450941/