PHP +运行bash脚本来创建文件 [英] PHP + Run bash script to create file
问题描述
在除了我的<一个href=\"http://stackoverflow.com/questions/11052162/run-bash-command-from-php/11052453#comment14460416_11052453\">$p$pvious问题,另一个问题出现了,我决定把它一个新的问题:
In addition to my previous question, another problem appeared and I decided to make a new question for it:
我目前正在调用PHP脚本,比运行bash脚本。 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包括:
The do.sh contains:
#! /bin/bash
echo 12;
dd if=/dev/urandom of=test.test bs=1048576 count=2
问题是以下几点:
The problem is following:
当我称之为 ./ 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.
这篇关于PHP +运行bash脚本来创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!