PHP File Browser/List

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thomaspark
Forum Newbie
Posts: 3
Joined: Sat Jun 06, 2009 4:36 pm

PHP File Browser/List

Post 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
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: PHP File Browser/List

Post by Darhazer »

thomaspark
Forum Newbie
Posts: 3
Joined: Sat Jun 06, 2009 4:36 pm

Re: PHP File Browser/List

Post 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?
Last edited by Benjamin on Mon Jun 08, 2009 1:49 pm, edited 1 time in total.
Reason: Changed code type from text to php.
thomaspark
Forum Newbie
Posts: 3
Joined: Sat Jun 06, 2009 4:36 pm

Re: PHP File Browser/List

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP File Browser/List

Post by Benjamin »

:arrow: Moved to PHP - Code
Post Reply