简体   繁体   English

PHP函数'scandir'在Windows上托管的WordPress上不起作用

[英]PHP function 'scandir' not working on WordPress hosted on windows

When i am using scandir function i get different results on linux and windows. 当我使用scandir函数时,在Linux和Windows上会得到不同的结果。

Windows i see only folder name Windows,我只能看到文件夹名称

Linux it does the job under 在Linux下完成工作

I run a check if WordPress files has been changed ? 我检查WordPress文件是否已更改?

function find_all_files($dir, $deep) 
{ 
  if(strpos($dir,"wp-content") == false){

    $root = scandir($dir); 
    foreach($root as $value) 
    { 
      if($value === '.' || $value === '..') {continue;} 
      if(is_file("$dir/$value")) {
            $tmpFile = "$dir/$value";
            if(5000000>@filesize($tmpFile)){

            $result[]="$tmpFile";
            }
            continue;
        } 

    $tmp = "$dir/$value";
      if(strpos($tmp,"wp-content") == false){   
        if($deep == true){
            foreach(@$this->find_all_files("$dir/$value",true) as $value) 
            { 
              $tmpFile = $value;
                  if(5000000>@filesize($tmpFile)){

                    $result[]="$tmpFile"; 
                    }
            } 
        }
      }
    }
    //var_dump($result);

    return $result; 
    }
}

I had a similar issue and it all came down to: 我有一个类似的问题,这全都归结为:

1) if you mean "running on windows" OS you need to include, and start from the drive directory (where server is installed) in $dir to scan. 1)如果您的意思是“在Windows上运行” 操作系统 ,则需要包含 操作系统 ,并从$dir 的驱动器目录 (安装服务器的位置)开始进行扫描。

2) Windows might be picky about separators, compare your $dir with Wordpress ABSPATH and try to use PHP constant DIRECTORY_SEPARATOR instead of your own '/' separators. 2) Windows可能对分隔符ABSPATH挑剔,将$ dir与Wordpress ABSPATH进行比较,并尝试使用PHP常量DIRECTORY_SEPARATOR而不是您自己的'/'分隔符。

3) And I asume you working with paths, not urls (http://localhost/wordpress/...plugin/dir/) . 3)我假设您使用的是路径, 而不是 URL (http://localhost/wordpress/...plugin/dir/) This is working for me on Windows 7, running Uniserver (LAMP): 在运行Uniserver(LAMP)的Windows 7上,这对我有用:

$rootfolder = 'startfolder';
$dir = plugin_dir_path(dirname( __FILE__ )).DIRECTORY_SEPARATOR.$rootfolder;
$files = array_slice(scandir($dir), 2);

However , you need to cut down the path end begin in the install dir with ABSPATH or something. 但是 ,您需要使用ABSPATH或其他方法来减少从安装目录开始的路径结尾。 But I recommend to test where your filescript is, like plugins folder, to not consume a huge stall on errors while working with this kind of stuff. 但是我建议测试文件脚本的位置,例如plugins文件夹,以免在处理此类内容时浪费大量的错误。

Hint! 暗示! The PHP docs about scandir has a lot off contributed functions about reading, retriving, scanning functions and issues. 有关scandir的PHP文档在阅读,检索,扫描功能和问题方面有很多贡献。 Take a look at: http://php.net/manual/en/function.scandir.php 看看: http : //php.net/manual/en/function.scandir.php

Important! 重要! Do not start messing with windows folder access, and if you do, take a RAW copy of whole www directory first, otherwise exported Worpdress installs could get messy on a Apache server live. 不要开始迷惑Windows文件夹的访问,如果要这样做,请首先获取整个www目录的RAW副本,否则导出的Worpdress安装可能会在Apache服务器上实时混乱

Remember, did you manage to install a new plugin from the Wordpress admin, you propably dont have a folder access issue. 记住,您是否设法通过Wordpress管理员安装了新插件,可能没有文件夹访问问题。

Hop this helps! 希望对您有所帮助!

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

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