Page 1 of 1

PHP File Browser/List

Posted: Sat Jun 06, 2009 4:41 pm
by thomaspark
Hi Guys,

I have a web site that I need to list/view the files stored in a directory. I wont to do this using PHP but I am not sure how to do it. Can someone write or give me some code that will do this for me. If Small images for Filesand Folders can be added that would help me alot.

The Directory that stores the files that I wont to list is called 'Files'.

It is located in my root directory example.com/files/.

Please can some one help me

Cheers
Thomas Park

Re: PHP File Browser/List

Posted: Sat Jun 06, 2009 4:43 pm
by Darhazer

Re: PHP File Browser/List

Posted: Mon Jun 08, 2009 1:30 pm
by thomaspark
Hi There,

I have this pace of code know.

Code: Select all

 
<?php
//Directory 
$handle=opendir("./files");
$projectContents = '';
while ($file = readdir($handle)) 
    {       
        $projectContents .= '<li><a href="files/'.$file.'">'.$file.'</a></li>';
    }
closedir($handle);
//end Dirctory
 
$pageContents = <<< EOPAGE
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
<html lang="en" xml:lang="en">
<head>
<title>Folders</title>
    <meta http-equiv="Content-Type" content="txt/html; charset=utf-8" />
    <!-- Style for Page -->
    <style type="text/css">
    ul.aliases, ul.projects, ul.tools {
    list-style: none;
    line-height: 24px;
}
ul.aliases a, ul.projects a, ul.tools a {
    padding-left: 22px;
    background: url(test1.php?img=pngFolder) 0 100% no-repeat;
}
</style>
<link rel="shortcut icon" href="test1.php?img=favicon" type="image/ico" />
</head>
<!-- Main Body -->
<body>
<font face="Arial">
    <h2>Files</h2>
    <ul class="projects">
    $projectContents
    </ul>
</font>
</body>
</html>
EOPAGE;
echo $pageContents;
?>
 
I wont to add icons to the side of the Files and Folders.
Can someone show me how to do this?

Re: PHP File Browser/List

Posted: Mon Jun 08, 2009 1:35 pm
by thomaspark
Sorry jus a little bit more.

I also don't wont the page to show the 'index.php' file.

Can someone edit my code to do both of these things.

Cheers
Thomas

Re: PHP File Browser/List

Posted: Mon Jun 08, 2009 1:50 pm
by Benjamin
:arrow: Moved to PHP - Code