gpt4 book ai didi

java - 我们可以从前端html页面在Linux服务器中创建文件吗?

转载 作者:太空宇宙 更新时间:2023-11-04 04:00:26 26 4
gpt4 key购买 nike

我想知道我们是否可以从浏览器中的html页面创建文件到linux服务器文件夹?我有一个创建 txt 文件的 shell 脚本。但是当我使用 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 或其他)有权执行该脚本。

关于java - 我们可以从前端html页面在Linux服务器中创建文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23198753/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com