How do you get PHP, Symlinks and __FILE__ to work together nicely?

前端 未结 6 1693
既然无缘
既然无缘 2020-12-02 15:19

On localhost. I have the following directory structure:

/share/www/trunk/wp-content/plugins/otherfolders

/share/www/portfolio/wp-content/s

6条回答
  •  被撕碎了的回忆
    2020-12-02 16:14

    Here is the solution to that issue: https://github.com/logical-and/symlink-detective

    $root = dirname(dirname(dirname(dirname(__FILE__))));
      if (file_exists(SymlinkDetective::detectPath($root.'/wp-load.php'))) {
          // WP 2.6
          require_once(SymlinkDetective::detectPath($root.'/wp-load.php'));
      }
    

    or you can try that

    try {
      $root = dirname(dirname(dirname(dirname(__FILE__))));
      require_once SymlinkDetective::detectPath($root.'/wp-load.php', '', 
        false /* this would throw an exception if file doesn't exists */);
    }
    catch (Exception $e) {
      // nothing to do if file doesn't exists
    }
    

提交回复
热议问题