【问题标题】:Can we create files in Linux server from front end html page?我们可以从前端 html 页面在 Linux 服务器中创建文件吗?
【发布时间】:2014-04-21 13:47:58
【问题描述】:

我想知道我们是否可以从浏览器中的 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

【问题讨论】:

  • 简短的回答是“是的,你可以”。对于与您的具体情况相关的答案,您需要提供实施的具体细节。
  • 嗨...我已经更新了详细信息。你能检查一下并告诉我我必须做些什么改变吗?感谢您的宝贵时间。

标签: java php ajax linux


【解决方案1】:

通过您的网络服务器执行脚本时,请注意您的网络服务器使用的环境很少与您作为 CLI 用户看到的环境相同。比如命令

sh test.sh

做出两个假设:sh 在您的 $PATH 中,test.sh 在当前工作目录中。当您的网络服务器尝试运行命令时,很可能这些都不正确。

为了获得更好的结果,请尝试同时包含命令和文件的完整路径。例如:

shell_exec('/bin/sh /var/www/html/scripts/test.sh');

最后,检查test.sh 上的可执行权限,以确保网络用户(httpd 或 apache 或其他)有权执行该脚本。

【讨论】:

  • 我已更新上述更改。它在命令行上工作正常,但是当我从浏览器尝试时,它没有给出错误消息,也没有在服务器上创建任何文件..你能告诉我我们是否可以在文件创建行打印输出..即捕获它返回的内容在 "echo "t1 test" > /home/siva/public_html/t1s" 行
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多