【问题标题】:Issue of "//" in UNIXUNIX 中的“//”问题
【发布时间】:2018-02-19 21:12:12
【问题描述】:
$('#lang_choice1').each(function () {
                    var lang = $(this).val();
                    $('#lang_files').empty();
                    $.ajax({
                        type: "POST",
                        url: '<?= site_url('translation/language/getDirContents') ?>',
                        data: {"lang":lang},
                        dataType:"json",
                        success: function (data) {
                            $.each(data,function(id,dir) //here we're doing a foreach loop round each directory with id as the key and directory as the value
                            {
                                var opt = $('<option />'); // here we're creating a new select option with for each directory
                                opt.val(dir);
                                opt.text(dir.substr(dir.lastIndexOf("\\")+1));
                                $('#lang_files').append(opt); //here we will append these new select options to a dropdown with the id
                            });
                            $("#lang_files").val($("#lang_files option:first").val());
                        }

                    });
                    return false;
                });

opt.text(dir.substr(dir.lastIndexOf("\\")+1)); 的使用在 UNIX 系统中引起了问题。但在 Windows 中它可以正常工作。在 UNIX 中它需要是“/” 我怎样才能使它兼容在基于 windows 和 unix 的系统中使用?

【问题讨论】:

标签: javascript jquery ajax


【解决方案1】:

我使用这种风格:

$dir = "/root/";   // Root directory to start at

function scanServer($dir){
    global $totalList;
    global $fileList;
    global $dirList;
    global $pathList;

    $files = scandir($dir);               // Obtain all files into an array
    foreach($files as $file){

      if($file != '.' && $file != '..'){
        if(is_dir($dir.'/'.$file)){       // Run self if it is a directory
          $dirList[] = $file;             // Creates a master list of all directories
          scanServer($dir.'/'.$file);
        }else{
          $fileList[] = $file;           // Creates a master list of all files
          $pathList[] = $dir.'/'.$file;  // Creates a master list of absolute paths

        }
      }
    }
  }

foreach($fileList as file){

   echo "<option value='".$file.">".$file."/>";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多