crazyjust Posted December 26, 2008 Share Posted December 26, 2008 hi. I had this script made for my site. I have 1 folder with 26 folders in that folder. The search I have only works for the main folder. Is there any way to make it search all the folders? All the folders contain mp3 if it means anything. I don't use mysql for this.Please look and tell me what you think.I'm not a coder, so I have no clue what to change if anything. Below is the code. Thanks in advance. <?php require_once("config.php"); require_once("class2.php"); define("e_PAGETITLE", "Music"); require_once(HEADERF); if (!USER) { $ns->tablerender("Error!", "You must login to view this page"); require_once(FOOTERF); exit; } ?> <?php function mksize($bytes) { if ($bytes < 1000 * 1024) return number_format($bytes / 1024, 2) . " kB"; elseif ($bytes < 1000 * 1048576) return number_format($bytes / 1048576, 2) . " MB"; elseif ($bytes < 1000 * 1073741824) return number_format($bytes / 1073741824, 2) . " GB"; else return number_format($bytes / 1099511627776, 2) . " TB"; } function getico($type) { switch(strtolower($type)) { case "mp3": return "mp3.gif"; break; case "exe": case "setup": case "msi": return "exe.gif"; break; case "zip": return "zip.gif"; break; case "rar": case "bin": case "tar": case "bz2": case "gz": case "z": case "7z": case "s7z": return "rar.gif"; break; case "mpg": case "mp4": case "mpeg": return "mp4.gif"; break; case "avi": return "avi.gif"; break; case "iso": case "img": case "cue": return "iso.gif"; break; case "vob": return "vob.gif"; break; default: return "unknown.gif"; break; } } $filedirxtra= (isset($_GET['dir']) ? htmlspecialchars($_GET['dir'])."/" : ""); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Downloads</title> <meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" /> <style type="text/css"> body { font-family: Verdana, Tahoma, Helvetica, Arial; font-size: 10pt; background-color: #000000; color: #FFFFFF; margin: 50px; } table.list tr td { border-bottom: 1px solid orange; } a { text-decoration: none; } a:hover { text-decoration: underline; } #txtsrch { background-image: url("icons/srchico.png"); background-position: left center; background-repeat: no-repeat; background-color: #cccccc; font-weight: bold; font-size: 11pt; padding-left: 25px; height: 20px; } #srchbtn { background: transparent; background-image: url("dl-icons/srchbtn.gif"); background-position: center center; background-repeat: no-repeat; height: 25px; width: 70px; border: none; } </style> <script type="text/javascript"> function preview(file) { var f = document.getElementById('fplayer'); f.src = "player.php?file="+file; } </script> </head> <body> </div> <!--Nav--> <div style="padding: 5px; margin: 10px; width: auto; height: 30px; border: 1px solid orange;"> <!-- Table hack required for IE--> <table cellpadding="0" cellspacing="0" border="0" width="auto" style="border: none;"> <tr> <td valign="middle" align="left"> <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <?php if ($filedirxtra != "") echo "<input type='hidden' name='dir' value='".$filedirxtra."' />"; ?> <input id="txtsrch" type="text" size="25" name="search" /> <input id="srchbtn" type="submit" value=" " /> </form> </table> </div> <div style="width: auto; margin: 0px; border: none; text-align: center;"> <iframe id="fplayer" frameborder="0" marginwidth="0" marginheight="0" width="320" height="70" src="player.php"></iframe> </div> <table class="list" width="auto" cellpadding="3" cellspacing="0" border="0" style="margin: 10px; border: 1px solid orange;"> <?php $kw = (isset($_GET['search']) ? trim($_GET['search']) : ""); $dir = opendir($filedir.$filedirxtra); while(false !== ($file = readdir($dir))) { if($file != "." && $file != "..") { $fext = explode(".", $file); if(!in_array(end($fext), $blockfiles) && is_file($filedir.$filedirxtra.$file)) { if(($kw != "" & preg_match("/$kw/i", $file)) || $kw == "") print("<tr><td><img src='".$icondir.getico(end($fext))."' title='".end($fext)."' alt='".end($fext)."' border='0'/></td><td width='99%'>".htmlspecialchars($file)."</td><td><span style='white-space: nowrap;'> ".mksize(filesize($filedir.$filedirxtra.$file))."</span></td><td><a href=\"".htmlspecialchars($filedir.$filedirxtra.$file)."\"><img src='".$icondir."download.gif' border='0' alt='DL' title='Download File: ".htmlspecialchars($file)."' /></a></td><td>".(in_array(end($fext), $prvfiles) ? "<a href=\"javascript:void(0);\" onclick=\"preview('".htmlspecialchars(addslashes($filedir.$filedirxtra.$file))."');\"><img src='".$icondir."preview.gif' border='0' alt='Preview' title='Preview File: ".htmlspecialchars($file)."' /></a>" : " ")."</td></tr>"); } elseif(is_dir($filedir.$filedirxtra.$file)) echo "<tr><td><img src='".$icondir."directory.gif' alt='directory' border='0' /></td><td colspan='4'><a href='?dir=".$filedirxtra.$file."'>$file</a></td>"; } } closedir($dir); ?> </table> <?php require_once(FOOTERF); exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/138438-need-help-with-search/ Share on other sites More sharing options...
.josh Posted December 26, 2008 Share Posted December 26, 2008 you can use glob to put get all the folder names into an array and foreach to loop through and run your code on each one. If those subfolders have subfolders that you want to in turn look into, you're going to want to look into recursion. Quote Link to comment https://forums.phpfreaks.com/topic/138438-need-help-with-search/#findComment-723834 Share on other sites More sharing options...
chronister Posted December 26, 2008 Share Posted December 26, 2008 Here is a post I made a while ago with a script to read through directories and create an array of all the files. It can be made to do a recursive seek and is very easy to use. http://www.phpfreaks.com/forums/index.php/topic,231216.msg1071733.html#msg1071733 Nate Quote Link to comment https://forums.phpfreaks.com/topic/138438-need-help-with-search/#findComment-723872 Share on other sites More sharing options...
crazyjust Posted December 26, 2008 Author Share Posted December 26, 2008 thank you for the replies and ideas. I figured it had to be possible but wasn't sure. Quote Link to comment https://forums.phpfreaks.com/topic/138438-need-help-with-search/#findComment-723992 Share on other sites More sharing options...
crazyjust Posted December 27, 2008 Author Share Posted December 27, 2008 you can use glob to put get all the folder names into an array and foreach to loop through and run your code on each one. If those subfolders have subfolders that you want to in turn look into, you're going to want to look into recursion. I'm sorry but I don't know where to put that lol. Could you give me an example? Quote Link to comment https://forums.phpfreaks.com/topic/138438-need-help-with-search/#findComment-724227 Share on other sites More sharing options...
crazyjust Posted December 28, 2008 Author Share Posted December 28, 2008 can someone please tell me what to change? Quote Link to comment https://forums.phpfreaks.com/topic/138438-need-help-with-search/#findComment-724741 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.