My boss gave me some script from a former employee.. the script is not commented. I have figured out most of what he did. What I need to know is how to get the code to search two different directories at the same time and print out both results.
can anyone help me out here?
<?PHP
set_time_limit(0);
function direcho($path, $srch) {
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><b>' . $file . '</b></li><ul>';
$con.=direcho($path."/".$file, $srch);
$fullsize=$fullsize + $fullsiz;
echo '</ul>';
$totaldirs++;
}
}
else { //if it's not a dir, just output.
$tab = " ";
$filesize = $tab . '(' . filesize ($path.'/'.$file) . ' kb)';
$num=strpos($file,$srch);
if (preg_match("/$srch/i", $file)) {
$path=str_replace(" ","%20",$path);
$filez=str_replace(" ","%20",$file);
$con.='<tr><td><a href="'. $path . "/" . $filez . '">'.$file.'</a></td><td><a href=index.php?action=email&file='.$filez.'&path='.$path.'>Email Me it.</a></td></tr>';
} else {
//echo "A match was not found.";
}
//$fullsize = $fullsize + filesize ($path.'/'.$file);
$filetotal++;
}
}
closedir($dir);
}
return $con;
//return $fullsize;
}
function send_mail($to, $file, $con, $type){
$data = chunk_split(base64_encode($con));
$mime_boundary = "<<<--==+X[".md5(time())."]";
$headers .= "From: Automatic <auto@domain.com>\r\n";
$headers .= "To: SomeOne <$to>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
$headers .= " boundary=\"".$mime_boundary."\"";
$message .= "This is a multi-part message in MIME format.\r\n";
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "\r\n";
$message .= "Email content and what not: \r\n";
$message .= "This is the file you asked for! \r\n";
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$file}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$file}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$ok = mail("$to", "file by email", $message, $headers);
}
session_start();
$act=$_REQUEST['action'];
mysql_connect("localhost", "user","password");
mysql_select_db("search");
switch($act){
case "login":
$amid=$_REQUEST['afid'];
$q = "SELECT * FROM users where uid='$amid';";
$res=mysql_query($q);
$num=mysql_num_rows($res);
$pw=$_REQUEST['pass'];
if($num<1){
echo "<script language=\"Javascript\">window.location='index.php?action=logfail';</script>";
}else{
$row=mysql_fetch_array($res);
$pw=$row['pass'];
$pass=$_REQUEST['pass'];
if($pass==$pw){
$_SESSION['login']=true;
echo "<script language=\"Javascript\">window.location='index.php';</script>";
}else{
echo "<script language=\"Javascript\">window.location='index.php?action=logfail';</script>";
}
}
break;;
case "logfail":
echo '<h2><font color=Red>We don\'t show a user and/or pw for that id</font></h2><br>';
echo '<table width=300><tr><td><form action="index.php" method="post" id="login" name="login">
<b>Username:</b></td><td><input type=text name=afid id=afid></td></tr>
<tr><td><b>Password: </b></td><td><input type=password name=pass id=pass></td></tr>
<tr><td></td><td><input type=submit name=submit><input type=hidden name=action value="login"></td></tr></table>';
break;;
case "search1":
$srch=$_POST['srch'];
echo "<html><head><meta http-equiv=\"refresh\" content=\"0;url=http://filesdomain/index.php?action=search&srch=$srch\"><script>
function on_Load(){
var finurl = \"http://filesdomain/index.php?action=search&srch=$srch\";
location.replace(finurl);
}</script> </head><body onload=\"javascript: on_Load();return false\">";
$stuff='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="100">
<param name="movie" value="search.swf">
<param name="quality" value="high">
<embed src="search.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="400" height="100"></embed></object>';
echo "<p align=center>$stuff</p></body></html>";
//echo "<script language=\"Javascript\">window.location='index.php?action=search&srch=$srch';</script\>";
break;;
case "search":
$srch=$_GET['srch'];
//echo $srch;
$sc = '<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function clearPreloadPage() { //DOM
if (document.getElementById){
document.getElementById(\'prepage\').style.visibility=\'hidden\';
}else{
if (document.layers){ //NS4
document.prepage.visibility = \'hidden\';
}
else { //IE4
document.all.prepage.style.visibility = \'hidden\';
}
}
}
// End -->
</SCRIPT>';
$load='<div id="prepage" style="position:absolute; font-family:arial; font-size:16; left:0px;
top:0px; background-color:white; layer-background-color:white; height:100%; width:100%;">
<table width=100%><tr><td><center>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0"
id="Movie1" width="400" height="80">
<param name="movie" value="Movie1.swf">
<param name="bgcolor" value="#F9F8F3">
<param name="quality" value="high">
<param name="allowscriptaccess" value="samedomain">
<embed type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer"
width="400" height="80"
name="Movie1" src="Movie1.swf"
bgcolor="#F9F8F3" quality="high"
swLiveConnect="true" allowScriptAccess="samedomain"
</embed>
</object></td></tr></table>
</div>';
$con.="<html><head>$sc</head><body onLoad=\"clearPreloadPage();\">$load<table border=1 bordercolor=cccccc>";
$con.=direcho("files/tapes", $srch);
//$con.=direcho("C:\My Documents",$search);
$con.= "</table>";
$con.= "<br><Br><a href=index.php>Back</a></body></html>";
print $con;
break;;
case "email":
echo "<form action=index.php method=post><table align=center>
<tr><td>Your Email: </td><td><input type=text name=to></td></tr>
<tr><td><input type=hidden name=file value=\"".$_GET['file']."\">
<input type=hidden name=path value=\"".$_GET['path']."\"><input type=hidden name=action value=enow></td><td>
<input type=submit name=submit value=Send></td></tr></table></form>";
break;;
case "enow":
$path=$_POST['path'];
$file=$_POST['file'];
$to = $_POST['to'];
$fp=fopen($path."/".$file,"r");
$con=fread($fp,filesize($path."/".$file));
fclose($fp);
$type=filetype($path."/".$file);
send_mail($to,$file,$con,$type);
echo "Mail sent to $to.";
echo "<br><a href=index.php>Back</a>";
break;;
default:
if($_SESSION['login']==true){
echo "<form action=index.php method=post>
<table align=center><tr><td>Search Files For: </td><td><input type=text name=srch><input type=hidden name=action value=search1></td></tr>
<tr><td></td><td><input type=submit name=submit value=Search></td></tr></table></form>";
}else{
echo '<table width=300><tr><td><form action="index.php" method="post" id="login" name="login">
<b>Username:</b></td><td><input type=text name=afid id=afid></td></tr>
<tr><td><b>Password: </b></td><td><input type=password name=pass id=pass></td></tr>
<tr><td></td><td><input type=submit name=submit><input type=hidden name=action value="login"></td></tr></table>';
}
break;;
}
?>