当我尝试在浏览器中打开树视图元素时,它不会在链接的完整位置打开文件

时间:2019-06-04 17:27:14

标签: php

单击树元素时...例如,该元素是jpg文件,浏览器应打开mysite.com/site/placeoffile/file.jpg,但尝试打开... mysite.com/ placeoffile / file.jpg,完全丢失了/ site /,有人可以帮助我吗?

该代码不是我的代码,我使用了abeautifulsite.net/php-file-tree提供的代码,它也不是完整的代码,因此请尽量简短,但我相信它是通过&return_link时最不相关。

if( count($file) > 2 ) { // Use 2 instead of 0 to account for . and .. "directories"
    $php_file_tree = "<ul";
    if( $first_call ) { $php_file_tree .= " class=\"php-file-tree\""; $first_call = false; }
    $php_file_tree .= ">";  
    foreach( $file as $this_file ) {
        if( $this_file != "." && $this_file != ".." ) {
            if( is_dir("$directory/$this_file") ) {
                // Directory
                $php_file_tree .= "<li class=\"pft-directory\"><a href=\"#\">" . htmlspecialchars($this_file) . "</a>";
                $php_file_tree .= php_file_tree_dir("$directory/$this_file", $return_link ,$extensions, false);
                $php_file_tree .= "</li>";
            } else {
                // File
                // Get extension (prepend 'ext-' to prevent invalid classes from extensions that begin with numbers)
                $ext = "ext-" . substr($this_file, strrpos($this_file, ".") + 1); 
                $link = str_replace("[link]", "$directory/" . rawurlencode($this_file), $return_link);
                //$link = str_replace("[link]", "$directory/" . urlencode($this_file), $return_link);
                $php_file_tree .= "<li class=\"pft-file " . strtolower($ext) . "\"><a href=\"$link\">" . htmlspecialchars($this_file) . "</a></li>";
            }
        }
    }
    $php_file_tree .= "</ul>";
}

它被调用如下...

                        <div class="Client-Data" id="Client-Data">
                        <?php if(isset($_SESSION['ClientID']) > 0){
                            $dir = $_SESSION['DataLocation'];
                            echo php_file_tree($dir, "javascript:window.open('[link]');");
                            ?><script type="text/javascript">
                                    window.onload = init_php_file_tree();
                            </script><?php
                        }?>
                    </div>

0 个答案:

没有答案