【问题标题】:Cant find PHP file with AJAX request找不到带有 AJAX 请求的 PHP 文件
【发布时间】:2013-12-25 16:36:41
【问题描述】:

我有一个 PHP 文件位于: /epcusers/toolsamc/users/epcvt/VT/CTM/CTM80/Billing/bin/runVT.php

它的权限是rwxrwxrwx (777),所有者是epcvt : users

我想通过从此文件发起的 AJAX 请求调用 runVT.php 文件: /var/www/html/evtgen/evt_run.php

我试过用这个 Javascript 来调用它:

var xmlhttp;
if (window.XMLHttpRequest) 
{
    xmlhttp=new XMLHttpRequest();
}
else
{
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.open("GET","/epcusers/toolsamc/users/epcvt/VT/CTM/CTM80/Billing/bin/runVT.php" ,true);
xmlhttp.send();

}

但我总是收到未找到文件的响应:

The requested URL /epcusers/toolsamc/users/epcvt/VT/CTM/CTM80/Billing/bin/runVT.php was not found on this server.

我也试过

xmlhttp.open("GET","../../../../epcusers/toolsamc/users/epcvt/VT/CTM/CTM80/Billing/bin/runVT.php" ,true);

xmlhttp.open("GET","epcusers/toolsamc/users/epcvt/VT/CTM/CTM80/Billing/bin/runVT.php" ,true);

但这也没有用。

为了检查我是否在文件夹中遗漏了一些东西,我去了 Unix 中的 /var/www/html/evtgen/ 文件夹并检查了两者:

vi /epcusers/toolsamc/users/epcvt/VT/CTM/CTM80/Billing/bin/runVT.php
vi ../../../../epcusers/toolsamc/users/epcvt/VT/CTM/CTM80/Billing/bin/runVT.php

他们都工作了(我得到了脚本文本)。我错过了什么?

【问题讨论】:

    标签: javascript php ajax unix directory


    【解决方案1】:

    在文档根目录 (/var/www/html/) 中创建一个文件,随意命名。

    在这个文件中,让它调用你的文件/epcusers/toolsamc/users/epcvt/VT/CTM/CTM80/Billing/bin/runVT.php

    例子:

    <?php
    
    require_once '/epcusers/toolsamc/users/epcvt/VT/CTM/CTM80/Billing/bin/runVT.php';
    

    任何不在文档根目录中的东西,都不能被客户端访问,除非你有一个 PHP 文件链接它,(或 apache 重写,但那是另一回事了)。

    【讨论】:

    • 谢谢,如果我最初想读取的 PHP 文件包含以下内容,那么 require_once() 是否有效:exec("RunVT.ksh" . " &gt; /dev/null &amp;");
    • 是的,它就像文件在根文件夹中一样。我没有要求您将 runVT.php 移动到文档根目录的原因是这样 bash 文件之类的依赖项仍然能够运行。为了安全起见,您可能希望exec 一个绝对路径,例如exec("/epcusers/toolsamc/users/epcvt/VT/CTM/CTM80/Billing/bin/RunVT.ksh &gt; /dev/null &amp;");
    • 最后一个问题,如果我无法访问文档根目录,我可以在/var/www/html/evtgen 文件夹中创建新的 php 文件,对吗?
    • 是的,只要文件是文档根目录的子文件,客户端就可以访问它。
    猜你喜欢
    • 2013-10-29
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多