使用PHP来确定其他服务器上是否存在外部文件

时间:2012-04-18 15:18:50

标签: php

我从html表单请求url,然后将其发布到php并运行if文件exsists,然后使用jquery我返回如果找到该文件它会覆盖报告消息。

看看我下面的代码..唯一的问题是我无法真正获得页面找到的响应,所以我认为PHP file_exsists命令有问题。

<?php

    header('Access-Control-Allow-Origin: *');  

    $filename = $_POST["find-one"];
    $filename2 = $_POST["find-two"];

?>
<html>
    <header>
        <title>404 Tool</title>
        <script type="text/javascript" src=".../1.7.1/jquery.min.js"></script>
        <?php
            if (file_exists($filename)) {
              echo "<script>
                      $(document).ready(function() { 
                        $('.report-one').text('File $filename is found.');
                      });
                    </script>";
            } else {
              echo "<script>
                      $(document).ready(function() { 
                        $('.report-one').text('File $filename doesn't exsist.');
                      });
                    </script>";
            }

            if (file_exists($filename)) {
              echo "<script>
                      $(document).ready(function() { 
                        $('.report-two').text('File $filename2 is found.');
                      });
                    </script>";
            } else {
              echo "<script>
                      $(document).ready(function() { 
                        $('.report-two').text('File $filename2 doesn't exsist.');
                      });
                    </script>";
            }
        ?>
    </header>
    <form method="post" action="<?php echo $PHP_SELF;?>"> 
      <input type="text" name="find-one" class="find-one"/>
      <p class="report-one">Waiting</p>
      <input type="text" name="find-two" class="find-one"/> 
      <p class="report-two">Waiting</p>
      <input type="submit" value="Search for 404's">
    </form>
  </body>
</html>

1 个答案:

答案 0 :(得分:0)

您只能使用file_exists检查服务器或网络共享中的文件,而不是其他服务器上的文件。

如果要检查其他服务器上的文件,则应使用cUrl

相关问题