运行bash脚本以在PHP中创建文件 [英] Run bash script to create file in PHP

查看:82
本文介绍了运行bash脚本以在PHP中创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了我的上一个问题,还出现了另一个问题,我决定为此提出一个新问题:

In addition to my previous question, another problem appeared and I decided to make a new question for it:

我当前正在调用一个比运行bash脚本还要多的php脚本. php脚本如下所示:

I am currently calling a php script that than runs a bash script. The php script looks like:

chdir('/home/');
$output = shell_exec('./do.sh');
echo "<pre>$output</pre>";

do.sh包含:

#! /bin/bash

echo 12;
dd if=/dev/urandom of=test.test bs=1048576 count=2

问题如下:

当我从终端呼叫./do.sh时,一切工作正常:test.test已创建,输出为12

When I call ./do.sh from the terminal everything works fine: test.test is created and the ouput is 12

但是,当我从php文件中调用它时,输出也是12,但是正在创建文件.由于我对bash脚本几乎一无所知,所以我不知道为什么会这样...

However, when I call it from my php file, the output is 12 aswell, but no file is being created. Since I know almost nothing about bash scripting, I have no idea why this is happening...

推荐答案

检查是否已启用PHP safe_mode.您必须在/etc/php.ini文件中将其关闭,并显然检查文件系统权限.

Check if PHP safe_mode is enabled. You have to turn it off in your /etc/php.ini file, and obviously check filesystem permissions.

这篇关于运行bash脚本以在PHP中创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆