简体   繁体   English

我需要帮助以php + ajax填充3个依赖的动态文件夹下拉列表

[英]I need help for populating 3 dependent dynamic folder drop downs with php+ajax

It would be great hep for me if any one can help me, I have a directory with 3 main folders A,B,C and Sub folders A1,A2,A3 in A folder like wise.., When the user select the folder A from 1st drop down,the Second drop down should be populated with sub folders in the Folder A.After Selecting second drop down the third drop down should be populated with sub sub folders on selection of sub sub folder and submit the files has to be displayed on the page with link to open the file. 如果有人可以帮助我,那对我来说将非常有用,我有一个目录,其中包含3个主文件夹A,B,C和子文件夹A1,A2,A3,在A文件夹中同样如此。.,当用户选择文件夹A时从第一个下拉列表开始,第二个下拉列表应在文件夹A中填充子文件夹。选择第二个下拉列表后,在选择子子文件夹时应在第三个下拉列表中填充子文件夹并提交文件在带有打开文件链接的页面上。 I know this would be done with the help of Ajax call,But i was a starter to php Kindly help me please... Also a alternate approach I have tried using glob function 我知道这将在Ajax调用的帮助下完成,但是我是php的入门者,请帮助我...也是我尝试使用glob函数的另一种方法

I dont know whats wrong with the Code no files are displaying in the page.. 我不知道代码有什么问题,页面中没有文件显示。

<?php

Session_start();
Error_reporting(E_ALL & ~E_NOTICE);
$reportname  = $_POST['Rep'];
$year  = $_POST['year'];
$customer  = $_POST['cus'];
$month= $_POST['month'];
$path= ".."."/".$reportname."/".$year."/".$customer."/".$month."/"; 
echo $path ."<br/>";
$files = glob($path."*.xlsx");
foreach($files as $file)
 {
echo $file;
 }
?>
$("#dropdown1").on("change", function() {

  $.ajax({
    url: "phpfile.php",
    type: 'POST',
    data: {
      folder: $(this).val()
    }
    success: function(data) {
      $("#dropdown2").html(data);
    }
  });
});

In phpfile.php 在phpfile.php中

$fileslist = scandir($_POST['folder']);
$str = "";
foreach($fileslist as $file) {
  if (is_dir($file)) {
    $str. = "<option>$file<option>";
  }
}
echo $str;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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