PDA

View Full Version : Webpage updating list


nvysel24
10-31-2009, 08:01 PM
Ok here is my problem i have a very basic website for a few tutorials to show my friends how to connect to my server to ftp. I have tons of movies that i let them borrow on that. since i have tons of movie i want to create wa web page with a list of all of them so they dont have to go searching through ftp.

my problem is that i dont want to update the list of every movie i get by editing a page
is there a way to build a web page so that it can read a folder and list out the movies, where every time i add a movie it adds what i have it named as.
the other option i have is i have a batch file that can create a list from a folder of all the names of the movies. is there a way to read from that file so that it updates the web page that way
Thanks in adv

_Aerospace_Eng_
10-31-2009, 08:11 PM
Does your host support php or any kind of server side language? You may want to look into something prebuilt.

I found this

http://freshmeat.net/projects/autoindex/

I think it allows you to create htaccess passwords so only your friends can see your videos.

nvysel24
10-31-2009, 09:49 PM
it does not support php but i can certainly install it. the only problem i see with that is it says its able have access to the files i only want a list because i do not want unwanted people using it.
any other suggestion? even though this one is a good possibility :D

Rowsdower!
11-01-2009, 03:27 AM
<?php
function num_files($dir, $recursive=false, $counter=0) {
// static $counter;
if(is_dir($dir)) {
if($dh = opendir($dir)) {
while(($file = readdir($dh)) !== false) {
if($file != "." && $file != "..") {
$counter = (is_dir($dir."/".$file)) ? num_files($dir."/".$file, $recursive, $counter) : $counter+1;
}
}
closedir($dh);
}
}
return $counter;
}
function compare_name($a, $b) {
return strnatcmp($a['name'], $b['name']);
}
function getFileList($dir) {
# array to hold return value
$retval = array();

# add trailing slash if missing
if(substr($dir, -1) != "/") $dir .= "/";

# open pointer to directory and read list of files
$d = @dir($dir) or die("Directory does not exist or is unavailable for mapping.");
while(false !== ($entry = $d->read())) {
# skip hidden files
if($entry[0] == ".") continue;
if(is_dir("$dir$entry")) {
$smk_new_dir = "$dir$entry/";
$smk_count = num_files($smk_new_dir,false,0);
if ($smk_count>0) {
$retval[] = array(
"name" => "$dir$entry/",
"type" => filetype("$dir$entry"),
"size" => 0,
"count" => $smk_count,
"subdir" => getFileList($smk_new_dir),
"lastmod" => filemtime("$dir$entry")
);
}
else {
$retval[] = array(
"name" => "$dir$entry/",
"type" => filetype("$dir$entry"),
"size" => 0,
"count" => $smk_count,
"lastmod" => filemtime("$dir$entry")
);
}
}
elseif(is_readable("$dir$entry")) {
$retval[] = array(
"name" => "$dir$entry",
"type" => mime_content_type("$dir$entry"),
"size" => filesize("$dir$entry"),
"lastmod" => filemtime("$dir$entry")
);
}
}
$d->close();

# sort alphabetically by name
usort($retval, 'compare_name');

//return the array
return $retval;
}
$directory="";
if ($_GET['dir']) {
$directory=$_GET['dir'];
}
$base_dir = $_SERVER['DOCUMENT_ROOT']."/".$directory."/";
$file_list = getFileList($base_dir);
function format_file_tree($item,$path) {
$trim_system_data = 0;
$result = "";
if ($item['type']=="dir") {
//trim off the trailing slash from the directory
$trim_system_data=1;
}
else {
//find length of the file extension
$trim_system_data = strlen(strrchr($item['name'],"."));
}
$result = " <li";
if ($trim_system_data==1) {
$result .= " class=\"directory\"";
}
$result .= ">".ucwords(str_replace("_"," ",substr($item['name'],strlen($path),strlen($item['name'])-strlen($path)-$trim_system_data))); //turn underscores into spaces
if ($trim_system_data==1) {
$result .= " <span class=\"file_count\">(".$item['count']." file";
if ($item['count']<>1) {
$result .= "s";
}
$result .= ")</span>";
if (count($item['subdir'])>0) {
$result .= "\n <ul>\n";
for ($i=0;$i<count($item['subdir']);$i++) {
$result .= format_file_tree($item['subdir'][$i],$item['name']);
}
$result .= " </ul>\n ";
}
}
$result .= "</li>\n";
return $result;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Directory<?php
if (!$directory=="") {
print " &raquo; ".ucwords($directory);
}
?></title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style type="text/css">
* {border:0;margin:0;padding:0;}
body {padding:5px;font-family:'trebuchet ms';font-size:15px;color:#aaa;}
#file_tree {/*padding:8px;*/overflow:auto;float:left;border:4px double brown;}
h1 {font-size:17px;font-weight:bold;color:#123456;border-left:1px solid #facedd;border-bottom:1px solid #facedd;padding-left:15px;width:280px;line-height:20px;/*14px;*/margin-bottom:5px;cursor:default;}
h1 .file_count {background-color:transparent;color:sienna;font-size:12px;}
ul {list-style-type:none;line-height:20px;}
#file_tree>ul {padding:8px;background-color:khaki;}
ul ul {margin-left:20px;}
a {color:#404040;font-size:14px;text-decoration:none;font-weight:bold;padding:2px 4px;margin-left:30px;}
a:hover {background-color:#8d5;}
li.directory {color:#000;font-weight:bold;background-color:lemonchiffon;margin-bottom:2px;padding:0px 10px 1px 2px;border:1px solid burlywood;margin-top:2px;}
li.directory ul li {color:#aaa;font-weight:normal;}
li.directory ul li.directory {color:#000;font-weight:bold;}
.file_count {background-color:maroon;font-size:11px;padding:0px 2px;color:#fff;}
ul ul {border-left:1px solid #000;border-bottom:1px solid #000;padding:5px;margin-bottom:5px;}
.directory:hover {background-color:lemonchiffon;color:#000;}
.directory .directory, .directory .directory:hover {background-color:lightyellow;color:#000;}
.directory .directory .directory, .directory .directory .directory:hover {background-color:floralwhite;color:#000;}
.directory .directory .directory .directory, .directory .directory .directory .directory:hover {background-color:#fff;color:#000;}
li {cursor:default;padding:0px 4px;}
li:hover {background-color:steelblue;color:#fff}
.directory li:hover {color:#fff;}
</style>
</head>
<body>
<h1><?php
if (!$directory=="") {
print "\"".ucwords($directory)."\" Directory";
}
else {
print "\"Root\" Directory";
}
?> <span class="file_count">(<?php print num_files($base_dir); ?> files)</span></h1>
<div id="file_tree">
<ul>
<?php
for ($i=0;$i<count($file_list);$i++) {
print format_file_tree($file_list[$i],$base_dir);
}
?>
</ul>
</div>
</body>
</html>

I had some free time so I wrote this as practice. It prints out a formatted filetree (but does not show extensions or create links to the files). The script also puts the filenames in title case and turns underscores into spaces. All-in-all it doesn't provide any direct way to get to your files and if you wanted to skip listing the directory folders (and list ONLY the files) it could be modified to do that.

It's currently set up to list all directories and files within the domain's (or subdomain's) root folder but it could also be modified to only work on a folder farther down the tree...

nvysel24
11-01-2009, 08:04 AM
holy crap that is amazing thank you so much

nvysel24
11-01-2009, 08:06 PM
so i got php instealled and working
when i run this script it gives me this error at line 57
Call to undefined function mime_content_type()
i would correct it myself but this is way to adv for me i can only do simple stuff.

_Aerospace_Eng_
11-01-2009, 11:35 PM
Are you using a windows server or an apache server?

And what version of php did you get installed?

nvysel24
11-02-2009, 01:45 AM
i have version 5.2.11 for php and i am actually using windows 7 as a server i installed all dependencies and stuff for IIS7

nvysel24
11-02-2009, 01:58 AM
ok well i got the code sorta working i was looking at what to edit and i got the line 52 error to go away but now another one on line 72
PHP Notice: Undefined index: dir in C:\inetpub\wwwroot\listmovies.php on line 72

_Aerospace_Eng_
11-02-2009, 08:41 AM
Change this
$directory="";
if ($_GET['dir']) {
$directory=$_GET['dir'];
}
to this
$directory="";
if (isset($_GET['dir'])) {
$directory=$_GET['dir'];
}

Rowsdower!
11-02-2009, 03:36 PM
Oops! Yes, that was a late addition to allow you to pass a $_GET variable in the URL to set the base directory on-the-fly.

My script was developed on a non-windows server. It worked like a charm there. Did you get it working properly on your server yet?

I had an afterthought that I should warn you about. If you keep the option alive for adding a $_GET variable to determine the base directory you would really, REALLY want to edit the code a bit so that users couldn't map your entire server. As it is, the script supports using "../" to navigate farther UP the directory chain than the www root. Just a word to the wise! :thumbsup:

Additional edit:

To prevent climbing up the folder tree you could use something like this:
$directory="";
if (isset($_GET['dir'])) {
if(strpos($_GET['dir'],"..") || strpos($_GET['dir'],"../")) {
$directory="";
}
else if (strpos($_GET['dir'],"..")!==0 && strpos($_GET['dir'],"../")!==0){
$directory=$_GET['dir'];
}
}

I don't know if that has covered all of the bases (I'm not that slick with folder navigation just yet), but this keeps me from navigating above the www folder with any means that I know of.

nvysel24
11-04-2009, 04:58 AM
thank you for the support guys. i have not got it working mainly because i don't have alot of time being a full time student and all. the one thing i did get to go away was all the errors but when i create the page that access the php page it will not list anything all it will do is say
FILES in bold and have a orange box below that your able to select and not do anything with