<html>
<body bgcolor=black text=white>
<?
#<title>Somewhat old file uploading script</title>
#########CONFIGURATION#################################
#######################################################
$tmpdir = "/web/edu/topics/php/upload/tmp/";
#######################################################

##############ERROR HANDLING FUNCTION##################
function error($msg){
        print("<head>
           <title>Error!</title>
               <style><!-- 
               form{ font-family: arial,helvetica }
                 td{ font-family: arial,helvetica } --></style></head>
               <body background=img/turn.gif><center>
               <table bgcolor=909090 cellpadding=20 border=1><tr><td>
                  <center>$msg<BR>
                  <form action=upload.php><input type=submit value=OKAY></form>
               </td></tr></table>");
}

if(empty($usrFile)){
     print("<HTML><HEAD><TITLE>File Upload</TITLE>
     <style><!--
      form{ font-family: arial,helvetica }
      td{ font-family: arial,helvetica }
      --></style>
     </HEAD><BODY bgcolor=202020 background=img/turn.gif><CENTER>
     <TABLE BGCOLOR=909090 BORDER=4 CELLPADDING=10 WIDTH=350><TR><TD>
     <h2>File Upload-O-Matic</h2>
     <LI>Insert the name of the file to be uploaded
     <LI>You must include the full directory path, i.e., c:\anydir\anyfile.ext
     <LI>10k maximum size 
     <FORM ENCTYPE=multipart/form-data ACTION=upload.php METHOD=POST>
     <INPUT TYPE=hidden name=MAX_FILE_SIZE value=10000>
     1. <INPUT NAME=usrFile SIZE=20 TYPE=file>
     <BR>
     2. <INPUT TYPE=Submit VALUE=\"Send this file\">
     </FORM>
     </TD></TR></TABLE><P>
     <TABLE BGCOLOR=909090 BORDER=4 CELLPADDING=10 WIDTH=350><TD>
     <h2>Look at stuff other people uploaded</h2>
     <CENTER><form action=tmp>
     <input type=submit value=\"View files\">
     </form></CENTER>
     </TD></TABLE>
     </CENTER>
     </BODY>
     </HTML>");
}else{
   if(file_exists("$tmpdir$usrFile_name"))
               error("File name $usrFile_name is already in use.");
   else if($CONTENT_LENGTH > $MAX_FILE_SIZE)
               error("File $usrFile_name is larger than the maximum allowed (10k).");
   else if( eregi(".php$",$usrFile_name) ){
    error("Sorry, can't upload php files.");
   }
   else{
     if(copy($usrFile, "$tmpdir$usrFile_name") && chmod("$tmpdir$usrFile_name",0444) ){
        print("<head><title>File Uploaded.</title></head>
               <body background=img/turn.gif><center>
               <table bgcolor=909090 cellpadding=20 border=1><tr><td>
               <center>File $usrFile_name uploaded.<BR>
               <form action=\"tmp/$usrFile_name\"><input type=submit value=VIEW></form>
               </td></tr></table>");
     }
     else
         error("Failed! Permission or disk space problem encountered.");
   }
}
?>