[英]Can we create files in Linux server from front end html page?
我想知道是否可以从浏览器中的html页面创建文件到linux服务器文件夹? 我有一个用于创建txt文件的外壳程序脚本。但是当我使用ajax从浏览器触发此脚本时,它不会创建任何文件。.我将所有权限授予了父目录,但仍然看不到文件创建或任何错误。
test.sh
echo "first sh"
java HelloWorld
echo "t1 test" > t1s
if [ ! -f t1s ]
then
echo "Shell File is not created .."
else
echo "Shell file is created.. "
fi
------
first.php
<?php
$output=shell_exec('sh test.sh');
echo "Hello Php \r\n";
echo $output;
echo "done \r\n";
?>
-----------
This is the output from command line:
Hello Php
hello first sh Shell file is created..
done
----------------
This is the output from broswer:
Hello Php hello first sh Shell File is not created .. done
通过Web服务器执行脚本时,请注意,Web服务器使用的环境很少与CLI用户看到的环境相同。 例如,命令
sh test.sh
有两个假设: sh
在$ PATH中,而test.sh
在当前工作目录中。 当您的网络服务器尝试运行命令时,很可能这两种都不是正确的。
为了获得更好的结果,请尝试包括命令和文件的完整路径。 例如:
shell_exec('/bin/sh /var/www/html/scripts/test.sh');
最后,检查对test.sh
的可执行权限,以确保Web用户(httpd或apache或其他)具有执行该脚本的权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.