944,196 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2789
  • PHP RSS
Jun 7th, 2005
0

Need help with directory displayer code

Expand Post »
Here's the situation. I created a program of sorts that allows the writer of our clubs newsletter to upload the newsletter each month to the "newsletter" folder. Then i have a php script that shows the content of the folder in an iframe on the home page so that users can download the .doc files.

The problem is that, with how the uploader php files are set up and the php directory displayer file is set up, i need to have them in the "newsletter" folder. Becouse of that, they show up in the directory listing for downloading. Does anyone know how to make the directory php script only show the .doc files and nothing esle??? This is the very last part of the program i'm building and i really need some expert advice on this. Is there a "if file is '.php', then hide this file" script i can add to the directory displaying script?

Please help. Thanks!

Curtis

capitalcitycorvairs.com
Chat-Forum-Videos-Photos
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
curtis_henken is offline Offline
5 posts
since May 2005
Jun 7th, 2005
0

Re: Need help with directory displayer code

Filter it with if command:

[php]$file = readdir(opendir('../newsletter/'))
// filter file
if(substr($file,-3,3) == "doc") {
// you may want to display the filesize
$fsize = filesize('../newsletter/' .$file);
echo $file." (".round($fsize/1024,2)." KB)";
}[/php]
Reputation Points: 10
Solved Threads: 7
Posting Whiz in Training
zippee is offline Offline
294 posts
since Jan 2005
Jun 7th, 2005
0

Re: Need help with directory displayer code

If you have more file types you want to display, you can use array to do it:
[php]
$file = readdir(opendir('../newsletter/'))
$ext = substr($file, -3, 3);
$accept = array('pdf','doc','xls','ppt','txt','zip');
if(in_array($ext, $accept)) {
//display file ...
}[/php]
Reputation Points: 10
Solved Threads: 7
Posting Whiz in Training
zippee is offline Offline
294 posts
since Jan 2005
Jun 7th, 2005
0

Re: Need help with directory displayer code

Thanks for your reply. Now this code you gave me will show the .doc files and hide the .php files correct?

Here is the entire script, can you show me where to implement your code? The initial code already displays file type, size, and date.

<?php

DEFINE("IMAGEROOT", "../images/"); #CHANGE /images/ TO THE PATH OF THE ASSOCIATED IMAGES

$textcolor = "#FFFFFF"; #TEXT COLOUR
$bgcolor = "#535353"; #PAGE BACKGROUND COLOUR

$normalcolor = "#0066FF"; #TABLE ROW BACKGROUND COLOUR
$highlightcolor = "#006699"; #TABLE ROW BACKGROUND COLOUR WHEN HIGHLIGHTED
$headercolor = "#003366"; #TABLE HEADER BACKGROUND COLOUR
$bordercolor = "#202750"; #TABLE BORDER COLOUR

?>
<html>
<head>
<title>Directory Listings of <? echo $_SERVER["REQUEST_URI"]; ?> </title>
<style type='text/css'>
<!--
body { color: <? echo $textcolor; ?>; font: tahoma, small verdana,arial,helvetica,sans-serif; background-color: <? echo $bgcolor; ?>; }
table { font-family: tahoma, Verdana, Geneva, sans-serif; font-size: 7pt; border: 1px; border-style: solid; border-color: <? echo $bordercolor; ?>; }
.row { background-color: <? echo $normalcolor; ?>; border: 0px;}
a:link { color: <? echo $textcolor; ?>; text-decoration: none; }
a:visited { color: <? echo $textcolor; ?>; text-decoration: none; }
a:hover, a:active { color: <? echo $textcolor; ?>; text-decoration: none; }
img {border: 0;}
#bottomborder {border: <? echo $bordercolor;?>;border-style: solid;border-top-width: 0px;border-right-width: 0px;border-bottom-width: 1px;border-left-width: 0px}
.copy { text-align: center; color: <? echo $textcolor; ?>; font-family: tahoma, Verdana, Geneva, sans-serif; font-size: 7pt; text-decoration: underline; }
//-->
</style>
</head>
<body>
<?php
clearstatcache();
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != substr($PHP_SELF, -(strlen($PHP_SELF) - strrpos($PHP_SELF, "/") - 1))) {

if (filetype($file) == "dir") {
//SET THE KEY ENABLING US TO SORT
$n++;
if($_REQUEST['sort']=="date") {
$key = filemtime($file) . ".$n";
}
else {
$key = $n;
}
$dirs[$key] = $file . "/";
}
else {
//SET THE KEY ENABLING US TO SORT
$n++;
if($_REQUEST['sort']=="date") {
$key = filemtime($file) . ".$n";
}
elseif($_REQUEST['sort']=="size") {
$key = filesize($file) . ".$n";
}
else {
$key = $n;
}
$files[$key] = $file;
}
}
}
closedir($handle);
}

#USE THE CORRECT ALGORITHM AND SORT OUR ARRAY
if($_REQUEST['sort']=="date") {
@ksort($dirs, SORT_NUMERIC);
@ksort($files, SORT_NUMERIC);
}
elseif($_REQUEST['sort']=="size") {
@natcasesort($dirs);
@ksort($files, SORT_NUMERIC);
}
else {
@natcasesort($dirs);
@natcasesort($files);
}

#ORDER ACCORDING TO ASCENDING OR DESCENDING AS REQUESTED
if($_REQUEST['order']=="desc" && $_REQUEST['sort']!="size") {$dirs = array_reverse($dirs);}
if($_REQUEST['order']=="desc") {$files = array_reverse($files);}
$dirs = @array_values($dirs); $files = @array_values($files);

echo "<table width=\"450\" border=\"0\" cellspacing=\"0\" align=\"center\"><tr bgcolor=\"$headercolor\"><td colspan=\"2\" id=\"bottomborder\">";
if($_REQUEST['sort']!="name") {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=name&order=asc\">";
}
else {
if($_REQUEST['order']=="desc") {#
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=name&order=asc\">";
}
else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=name&order=desc\">";
}
}
echo "File</td><td id=\"bottomborder\" width=\"50\"></a>";
if($_REQUEST['sort']!="size") {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=size&order=asc\">";
}
else {
if($_REQUEST['order']=="desc") {#
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=size&order=asc\">";
}
else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=size&order=desc\">";
}
}
echo "Size</td><td id=\"bottomborder\" width=\"120\" nowrap></a>";
if($_REQUEST['sort']!="date") {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=date&order=asc\">";
}
else {
if($_REQUEST['order']=="desc") {#
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=date&order=asc\">";
}
else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=date&order=desc\">";
}
}
echo "Date Modified</a></td></tr>";

$arsize = sizeof($dirs);
for($i=0;$i<$arsize;$i++) {
echo "\t<tr class=\"row\" onMouseOver=\"this.style.backgroundColor='$highlightcolor'; this.style.cursor='hand';\" onMouseOut=\"this.style.backgroundColor='$normalcolor';\" onClick=\"window.location.href='" . $dirs[$i] . "';\">";
echo "\t\t<td width=\"16\"><img src=\"" . IMAGEROOT . "folder.gif\" width=\"16\" height=\"16\" alt=\"Directory\"></td>";
echo "\t\t<td><a href=\"" . $dirs[$i] . "\">" . $dirs[$i] . "</a></td>";
echo "\t\t<td width=\"50\" align=\"left\">-</td>";
echo "\t\t<td width=\"120\" align=\"left\" nowrap>" . date ("M d Y h:i:s A", filemtime($dirs[$i])) . "</td>";
echo "\t</tr>";
}

$arsize = sizeof($files);
for($i=0;$i<$arsize;$i++) {
switch (substr($files[$i], -3)) {
case "jpg":
$img = "jpg.gif";
break;
case "gif":
$img = "gif.gif";
break;
case "zip":
$img = "zip.gif";
break;
case "png":
$img = "png.gif";
break;
case "avi":
$img = "move.gif";
break;
case "mpg":
$img = "move.gif";
break;
default:
$img = "what.gif";
break;
}

echo "\t<tr class=\"row\" onMouseOver=\"this.style.backgroundColor='$highlightcolor'; this.style.cursor='hand';\" onMouseOut=\"this.style.backgroundColor='$normalcolor';\" onClick=\"window.location.href='" . $files[$i] . "';\">\r\n";
echo "\t\t<td width=\"16\"><img src=\"" . IMAGEROOT . "$img\" width=\"16\" height=\"16\" alt=\"Directory\"></td>\r\n";
echo "\t\t<td><a href=\"" . $files[$i] . "\">" . $files[$i] . "</a></td>\r\n";
echo "\t\t<td width=\"50\" align=\"left\">" . round(filesize($files[$i])/1024) . "KB</td>\r\n";
echo "\t\t<td width=\"120\" align=\"left\" nowrap>" . date ("M d Y h:i:s A", filemtime($files[$i])) . "</td>\r\n";
echo "\t</tr>\r\n";
}
echo "</table><div align=\"center\"><a href=\"http://evoluted.net/directorylisting.php\" class=\"copy\">Directory Listing Script</a>. <a href=\"http://evoluted.net/\" class=\"copy\">&copy 2003-2004 Ash Young</a></div>";
?>
</body>
</html>


Thanks for your help!

Curtis
Reputation Points: 10
Solved Threads: 0
Newbie Poster
curtis_henken is offline Offline
5 posts
since May 2005
Jun 8th, 2005
0

Re: Need help with directory displayer code

If not mistaken, should be after this lot, and before print the values.
[PHP]#ORDER ACCORDING TO ASCENDING OR DESCENDING AS REQUESTED
if($_REQUEST['order']=="desc" && $_REQUEST['sort']!="size") {$dirs = array_reverse($dirs);}
if($_REQUEST['order']=="desc") {$files = array_reverse($files);}
$dirs = @array_values($dirs); $files = @array_values($files);
[/PHP]
Reputation Points: 10
Solved Threads: 7
Posting Whiz in Training
zippee is offline Offline
294 posts
since Jan 2005
Jun 8th, 2005
0

Re: Need help with directory displayer code

Hey Zippee,

I inserted your code into the script and nothing changed. Is there any way you could try this script with your code in it and let me know what you find?

Thanks,

Curtis
Reputation Points: 10
Solved Threads: 0
Newbie Poster
curtis_henken is offline Offline
5 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Please help with email form script
Next Thread in PHP Forum Timeline: Simple Email Form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC