2012-04-18 35 views
1

我正在從html表單請求url,然後發佈到php並運行一個if文件exsists,然後用jquery我返回if找到該文件將覆蓋報告消息。使用PHP來確定外部文件是否存在於其他服務器上

看看我的代碼在下面..唯一的問題是,我一直沒有能夠實際得到一個頁面找到響應,所以我想有一個錯誤的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> 

回答

0

您可以使用file_exists只檢查文件服務器上或網絡共享,而不是在其他服務器上的文件。

如果你想檢查其他服務器上的文件,你應該使用cUrl

相關問題