Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help setting up Script

Status
Not open for further replies.

MSW

IS-IT--Management
Jan 9, 2002
48
US
Hello; I'm new to PHP scripts and I'm not at all sure what I'm doing as of yet..

I have a windows server running IIS and I have installed php 4.3 and have run a few tests to see that it is installed correctly..

All I want to do is to display a folders contents on a web page but everything I have tried doesn't seem to work.

Can anyone point me to a script file that should work..

Thanks..Scott
 
Fetching and displaying the listing of the contents of a filesystem directory will require the use of the opendir() function.

There is example code on the online manual page for the function.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I have tried that and all I get is a blank page..

What am I missing when I just cut and past the opendir() sample from that page?

Here's a link to my test page just incase you want to see what I'm doing..


Thanks
 
Did you just cut-and-paste, or did you change the code to match your system? At the very least the the $dir variable should be changed to match your filesystem.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I did just do a cut and past and then attempted to work with the $dir variable but I'm lost as to what it is really looking for? Should I put my folder path in place of the $dir = "/tmp/"; line??? If so what is the syntax it needs because I think I've tried every combination with no luck..

<?php
$dir = "/tmp/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
}
closedir($dh);
}
}
?>

Thanks
 
One thing to keep in mind about PHP's filesystem and directory functions. They aren't constrained to the document root of the current web site. You can open a directory or file any where on the server's filesystem.



Another thing to keep in mind is how PHP's string delimiters, "'" (singlequote) and '"' (doublequote) affect strings, particularly as they affect Win32 directory paths. Strings delimited with doublequotes are interpolated -- that is the contents of the string are interpreted by the language engine. Backslashes are used in strings to escape the following character, for example "\n" to represend a newline. If you're using backslashes in the string, "c:\temp" (inside doublequotes) will be interpreted as "c:[tab]emp", as "\t" delineates the tab character.

There are two workarounds: use singlequoted strings or use forward slashes in Win32 paths.

Now that I've said all that, on what OS are you running PHP, and how are you trying to represent your directory name?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top