mike760534211 Posted January 6, 2007 Share Posted January 6, 2007 i have a script that lists the contents of the items in the dorectory where the index.php resides. but when it lists the files it lists everything. i want it to parse out(not show) 2 files types by extention. no matter what i do i cant get it to work correctly. can someone please help me out. i have included the directory list script below in the hopes that someone might have a solution for me.<?phpfunction direcho($path) { global $filetotal, $fullsize, $totaldirs; $ignore = array(".php",".jpg"); $ext = strtoupper(substr(strrchr($file_name, "."), 1)); if ($dir = opendir($path)) { while (false !== ($file = readdir($dir))) { if (is_dir($path."/".$file)) { // if it's a dir, check it's contents too if ($file != '.' && $file != '..' ) { // but dont go recursive on '.' and '..' echo '<li><img src="folder.jpg"><a href =\ $file )><b>' . $file . '</b></a></li><ul>'; direcho($path."/".$file ); echo '</ul>'; $totaldirs++; } } else { //if it's not a dir, just output. $tab = " "; $filesize = $tab . '(' . filesize ($path.'/'.$file ) . ' bytes)'; echo '<li><A HREF=' . $file . '>' . $file . '</A></li>'; $fullsize = $fullsize + filesize ($path.'/'.$file); $filetotal++; } } closedir($dir);}}direcho('.');$fullsize = round($fullsize / 1024 / 1024, 2);echo "<font size=\"2\" face=\"Arial, Helvetica, sans-serif\"><b>Total files</b> - $filetotal files<br><b>Total dirs</b> - $totaldirs directories<br><b>Total size</b> - $fullsize MB<br>";?>any help would be greatly appreciated.mike Link to comment https://forums.phpfreaks.com/topic/33096-directory-list-script-help-for-n00b/ Share on other sites More sharing options...
taith Posted January 6, 2007 Share Posted January 6, 2007 glob() is MUCH easier for this type of work...[code]<?$files = array_merge(glob("*.php"),glob("*.gif"));print_r($files);?>[/code] Link to comment https://forums.phpfreaks.com/topic/33096-directory-list-script-help-for-n00b/#findComment-154216 Share on other sites More sharing options...
Hypnos Posted January 6, 2007 Share Posted January 6, 2007 Try this:[code=php:0]<?phpfunction direcho($path) { global $filetotal, $fullsize, $totaldirs; $ignore = array(".php",".jpg"); $ext = strtoupper(substr(strrchr($file_name, "."), 1)); if ($dir = opendir($path)) { while (false !== ($file = readdir($dir))) { if (is_dir($path."/".$file)) { // if it's a dir, check it's contents too if ($file != '.' && $file != '..' ) { // but dont go recursive on '.' and '..' echo '<li><img src="folder.jpg"><a href =\ $file )>' . $file . '[/url]</li><ul>'; direcho($path."/".$file ); echo '</ul>'; $totaldirs++; } } elseif(!stripos($file, ".php") && !stripos($file, ".jpg")) { //if it's not a dir, just output. $tab = " "; $filesize = $tab . '(' . filesize ($path.'/'.$file ) . ' bytes)'; echo '<li><A HREF=' . $file . '>' . $file . '[/url]</li>'; $fullsize = $fullsize + filesize ($path.'/'.$file); $filetotal++; } } closedir($dir);}}direcho('.');$fullsize = round($fullsize / 1024 / 1024, 2);echo "<font size=\"2\" face=\"Arial, Helvetica, sans-serif\">Total files - $filetotal filesTotal dirs - $totaldirs directoriesTotal size - $fullsize MB";?>[/code]Looks like part of your problem is that the code you were trying wasn't in the while loop. Link to comment https://forums.phpfreaks.com/topic/33096-directory-list-script-help-for-n00b/#findComment-154274 Share on other sites More sharing options...
mike760534211 Posted January 7, 2007 Author Share Posted January 7, 2007 The corrections worked great thanks. it does exactly what it should. but now since the links go directly to a media file they auto play in the browser. is there a way to force it to download instead of playing in the browser? Link to comment https://forums.phpfreaks.com/topic/33096-directory-list-script-help-for-n00b/#findComment-154772 Share on other sites More sharing options...
trq Posted January 7, 2007 Share Posted January 7, 2007 Take a look in the [url=http://www.phpfreaks.com/forums/index.php/board,41.0.html]FAQ/Code snippet repository[/url]. Link to comment https://forums.phpfreaks.com/topic/33096-directory-list-script-help-for-n00b/#findComment-154774 Share on other sites More sharing options...
mike760534211 Posted January 7, 2007 Author Share Posted January 7, 2007 useing that forces the code form the page to download. not the actual file itsself Link to comment https://forums.phpfreaks.com/topic/33096-directory-list-script-help-for-n00b/#findComment-154783 Share on other sites More sharing options...
trq Posted January 7, 2007 Share Posted January 7, 2007 You will need to customise it to your needs. Link to comment https://forums.phpfreaks.com/topic/33096-directory-list-script-help-for-n00b/#findComment-154786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.