开发者

How to get a php script to print/work

开发者 https://www.devze.com 2023-02-28 17:01 出处:网络
I have: function ListFiles($dir) { if($dh = opendir($dir)) { $files = Array(); $inner_files = Array(); while($file = readdir($dh)) {

I have:

function ListFiles($dir) {

    if($dh = opendir($dir)) {

        $files = Array();
        $inner_files = Array();

        while($file = readdir($dh)) {
            if($file != "." && $file != ".." && $file[0] != '.') {
                if(is_dir($dir . "/" . $file)) {
                    $inner_files = ListFiles($dir . "/" . $file);
                    if(is_array($inner_files)) $files = array_merge($files, 

$inner_files); 
                } else {
                    array_push($files, $dir . "/" . $file);
                }
            }
        }

        closedir($dh);
        return $files;
    }
}


foreach (Li开发者_如何学GostFiles

('www.fromtheabsenceofagirlfriendcomesthis.net/sounds/folder1') as $key=>

$file){
    echo $file ."<br />";
}  

From somewheres on the web, & when I test it (I eventually want to return a random file name into a href - so tips welcome) I get null. & I try opening the php file via the browser, (null), & I tried calling it from a "php" page:

  <!DOCTYPE HTML>
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>

    <script language="JavaScript" type="text/javascript"
    src="http://fromtheabsenceofagirlfriendcomesthis.net/sounds/randomfil

    e.php"
    <script>
    </BODY>
    </HTML>

But null. What's my problem?


You can't read/list a directory over HTTP. You'll need to use a different protocol to list a directory over the internet: FTP, SSH, etc. You'll need access to the remote server to do this. If the only thing you can use is HTTP, you'll need to retrieve the webpage (= the HTML document) and parse it yourself.


try rewrite www. -> not www, if your want use this at same domain. Bua am almost sure that this is bad practice, try using http:// for glob() of directory call's use directory listing og glob() as ... functions.


You are trying to load raw html output as a script:

<script language="JavaScript" type="text/javascript"
    src="http://fromtheabsenceofagirlfriendcomesthis.net/sounds/randomfile.php"
<script>

This will never work, as your directories+break tags are NOT valid javascript code, so the whole "script" gets nuked because of syntax/parsing errors. If you want to dynamically load directory listings into a script, you'll have to surround the generated directory listing with valid javascript code, and/or fetch the listing from another script via an AJAX call.

0

精彩评论

暂无评论...
验证码 换一张
取 消