1

I am trying to get this script to work. it opens up a directry and lists the files in the directory. I have copied this code from somewhere else and the problem is that this php file is hosted on an apache server not my localhost. what is the correct $dir_name = "c:/"; to use?

The file is in this directory /domains/domainxxxx.com.au/public_html/lsitfiles.php so would I use domainxxxx.com.au/public_html/lsitfiles.php ?

<?php

$dir_name = "c:/";

$dir = opendir($dir_name);

$file_list = "<ul>";

while ($file_name = readdir($dir)) {
    if(($file_name != ".") && (file_name != "..")) {
    $file_list .= "<li>$file_name"; 
                               }
}

$file_list.= "<ul>";

closedir($dir);

?>

<HTML>
<BODY>

<p>Files in: <? echo "$dir_name"; ?></p>
<? echo "$file_list"; ?>


</BODY>
</HTML>

3 Answers 3

1

Depends which folder you want to scan.

Obviously, you cannot scan any folder on client's computer. I guess you know that.

If you want to scan folder where the script resides it's best to use:

$dir_name = dirname(__FILE__);
Sign up to request clarification or add additional context in comments.

Comments

0

$dir_name is the folder you want to scan. Where you upload your script, you can specify the folders there from using absolute or relative paths upward and backward eg ../foldername or myfolder/myfolder2.

2 Comments

The file is in this directory /domains/domainxxxx.com.au/public_html/lsitfiles.php so would i use domainxxxx.com.au/public_html/lsitfiles.php ?
Maybe first tell us WHICH folder you want to scan? The folder where script resides? Home folder on server?
0

Depends on OS. In Linux it would be '/'. P.S. If server is configured properly, you should not be able to read '/' (or 'c:/').

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.