<HTML>
<HEAD>
<TITLE>File Upload</TITLE>
</HEAD>
<BODY bgcolor="#99CCCC" background="../graphics/web3.jpg">
<center>
<h2>File Upload</h2>

<?
   //check for file upload
   if(isset($UploadedFile) && $UploadedFile != "")
   {
      $ok = 0;
      $listfile = $uname.".dat";
    
      if($uname != "" && $pword != ""){
        if(file_exists($listfile)){
          $pass = file("ul.txt");
          $un = substr($uname,0,2);
          $pw = substr($pword,0,2);
           
          for($index = 0; $index < count($pass); $index++){
            if(ereg("^$un",$pass[$index])){
              if(ereg(":$pw",$pass[$index])){
                $ok = 1;
                break;
              }
            }
          }              
        }
      }
      else{
        print("You need to supply your username and password<p><HR><p>\n");
      }
  
      if($destname != ""){
        $filename = $destname;
      }
      else{
        $filename = $UploadedFile_name;
      }

      if($altpath != ""){ 
        $dest = $altpath.$filename;
      }
      else{
        $dest = $copyto.$filename;
      }

      if(file_exists($dest) && $ok){
        if(isset($overwrite)){
          $ok = $ok;
        }
        else{
        $ok = 0;
        print("A file named $dest already exists.<br>If you still want to upload this file either choose another name in the <i>Rename on U/L</i> field or delete the existing file.<p><HR><p>\n");
        }
      }
     
      if($ok){
      
        if(copy($UploadedFile, $dest )){
          print("<table border=0><td>");
          print("Uploaded file: $UploadedFile_name [$UploadedFile]<br>\n");
          print("Copied to: $dest<BR>\n");
          print("Size: $UploadedFile_size <BR>\n");
          #print("Type: $UploadedFile_type <BR>\n");
          mail("shambhala@telusplanet.net", "MVD file upload", "$UploadedFile_name [$UploadedFile] copied to $dest");
          if($copyto == "/usr/local/www/data/mvd/" && $altpath == ""){
            $FILE = fopen($listfile,"a");
            fputs($FILE, "$filename,Uploaded file\n");
            fclose($FILE); 
          }
        }
        else{
          print("$UploadedFile_name [$UploadedFile] could not be copied to $dest<BR>\n");
        }                
        unlink($UploadedFile);
        print("</td></table><p><HR><p>\n");
      }
      else {
        unlink($UploadedFile);
        print("$UploadedFile_name not uploaded<p>Possible reasons include an invalid username/password combo or a non-existent file.<p><HR><p>\n");        
      }
   }
?>

<table border=2 cellpadding=8 bgcolor="#99CCCC">
<td><center><br><b>Name of the local file you would like to upload<br></center></b>
<FORM ENCTYPE="multipart/form-data" 
	ACTION="upl.php" METHOD="post"> 
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="102400"> 
<center><INPUT NAME="UploadedFile" SIZE=30 TYPE="file"></center><p>
Choose a location for this file:<br>
<input type="radio" name="copyto" value="/usr/local/www/data/mvd/" CHECKED> /mvd <font size=1> Put html files here (will be added to your private file list)</font><br>
<input type="radio" name="copyto" value="/usr/local/www/data/graphics/"> /graphics <font size=1> Put gifs, jpegs and other files here</font><br>
<p>
<center><INPUT TYPE='text' name='destname' size=30> Rename on U/L<br><font size=1> (If you want to change the name it will have on the site)</font><p>
<?
  if($uname == "carve"){
    print("<center><INPUT TYPE='text' name='altpath' size=30> Other Directory<P> \n");
    print("<INPUT TYPE='checkbox' name='overwrite' value='on'> Overwrite if file already exists</center><P>\n");
  }
?>
<center><table><td>
<INPUT TYPE=TEXT SIZE=23 NAME="uname"> username<br>
<INPUT TYPE=password SIZE=23 NAME="pword"> password</td></table>
<p>
<INPUT TYPE="submit" VALUE="Upload"></center></FORM></td></table><p>
<hr size=2>
<?
print("<A HREF=\"mvladmin.cgi?Action=Add/Edit%20Entry&title=/private&uname=$uname&pword=$pword\">");
?>
 [ Private File Form ] </a>&nbsp;&nbsp;<a href="http://global-dialog.org/" target=_top> [ Global Dialog Home ] </a>&nbsp;&nbsp;<a href="http://global-dialog.org/mvd"> [ MVD Home ] </a>&nbsp;&nbsp;<a href="mvl.cgi?NextName=List"> [ List ] </a><hr>
<br>
</center>
</BODY>
</HTML>
