简体   繁体   中英

jQuery/AJAX Solution to check if folder exists in a network share

I'm currently developing an internal website to provide automated account maintenance functions to end users. Part of the site is an admin portal that our L1 and L2 technicians use to provide more advanced services. I need that part of the site to see if the Powershell scripts it leverages has created a new folder yet. That folder exists on a NetAPP fileshare.

The site is coded in PHP using jQuery and AJAX scripts for file checks, etc. Most of the file checking happens in the root directory of the website, so it's easy to handle using AJAX. What I'm looking for is how to check the fileshare similar to this:

var myVar = setInterval(checkPRT, 5000);
function checkPRT(){
$.ajax({
      type: 'GET', 
      url: \\FILESHARE\folder\path\,
      success: function(data) {
        //alert('success!');
        window.location.href = "complete.php";
      }, error: function (data) {
        alert('failed');
      }
});
}

This doesn't seem to work. Based on my research and what I've read on other questions related to this, AJAX can't check file locations only other URLs (with the allowglobal setting set to true). I'm still relatively new to jQuery, JavaScript, and AJAX so forgive me if I'm asking a dumb question: What is the best way to do this? I'm not limited on what languages I can use, but I'd like to keep it in the PHP/JavaScript family if possible.

Thanks!

You need to send an AJAX request to a PHP file where you can check whether the folder exist or not.

jQuery code:

function checkPRT(){
$.ajax({
      type: 'GET', 
      url: 'check_file.php',
      data: {folder_path: '\\FILESHARE\folder\path\'},
      success: function(data) {
        //alert('success!');
        if(data=='true'){ 
        window.location.href = "complete.php";
        }
      }, error: function (data) {
        alert('failed');
      }
});
}

PHP Code => check_file.php :

<?php

if(isset($_GET['folder_path']) && !empty($_GET['folder_path'])){
  if(file_exists($_GET['folder_path']){
     echo 'true';
  }else{
     echo 'false';
   }

}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM