PX : code

File Upload for Wind by Michael Grier
Download this code


<%
   // ASP-style tags are okay in PHP 3.0.4 and above; some HTML editors recognize these tags

   // This code only works on Windows-based servers ;)
   // Some lines, like this one, are longer than this window and may have wrapped; you can get the original, if necessary, at the address shown in the code description

   // File Upload Script for PHP/3 for Windows

   // Released under the terms of the public GNU license
   // Based upon code written by Rasmus Lerdorf and Boaz Yahav
   // Modified for Windows by Michael Grier
   // E-mail: bigmike@bigmweb.com

   // You need to write-enable a directory, named "upload", below the one you place this script in
   // On Windows NT, you can do this with a DOS program named CACLS
   // Directions for this can be found at "http://www.bigmweb.com/home/cacls.html"



if($action1){                                                    // if files have been uploaded, process them
%>                                                                 

   <html>
   <head>
   <title>File Upload Results</title>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   </head>

   <body bgcolor="#FFFFFF" text="#000000">
   <p><font face="Arial, Helvetica, sans-serif"><font size="+1">File Upload Results</font><br><br>

   <%
   set_time_limit(60);                                           // make reasonably sure the script does not time out on large files
   $path1 = AddSlashes(dirname($PATH_TRANSLATED))."\\upload\\";  // assign our path in a form PHP for Windows understands
   for($i = 0; $i < 4; $i++){                                    // loop through the 4 possible files
      switch($i){                                                // retrieve a file pointer from the temp directory
         case 0:
            $source = $file1;
            $source_name = $file1_name;
            break;
         case 1:
            $source = $file2;
            $source_name = $file2_name;
            break;
         case 2:
            $source = $file3;
            $source_name = $file3_name;
            break;
         case 3:
            $source = $file4;
            $source_name = $file4_name;
            break;
      }
      if(($source <> "none")&&($source <> "")){                  // see if the file exists; non-existing file has name of "none"
         if($error1 <> 1){                                       // no need to copy a file if directory not write-enabled
            $dest = $path1.$source_name;                         // append file name to our path
            if(copy($source,$dest)){                             // copy the file from the temp directory to the upload directory, and test for success
               echo "$source_name has been uploaded<br>\n";         
            }
            else {
               echo "Upload directory not write-enabled\n";      // you need to write-enable the upload directory
               $error1 = 1;                                      // set flag
            }
         }   
         unlink($source);                                        // delete the file from the temp directory
      }
   }
   %>

   <br><a href="upload.php3">Back</a>
   </font></p>
   </body>
   </html>

<%
}
else {                                                           // else, prompt for the files
                                                                 // files will be uploaded into the server's temp directory for PHP
   %>

   <html>
   <head>
   <title>File Upload</title>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   </head>

   <body bgcolor="#FFFFFF" text="#000000">
   <p><font face="Arial, Helvetica, sans-serif"><font size="+1">File Upload</font><br><br>
   If your browser is upload-enabled, you will see &quot;Browse&quot; (Netscape, Internet Explorer) or &quot;. . .&quot; (Opera) buttons below. Use them to select file(s) to upload, then click the &quot;Upload&quot; button. After the files have been uploaded, you will see a results screen.<br>
   <form method="post" enctype="multipart/form-data" action="upload.php3">
           <input type="hidden" name="MAX_FILE_SIZE" value="400000">
           <input type="hidden" name="action1" value="1">
   File 1: <input type="file" name="file1" size="30"><br>
   File 2: <input type="file" name="file2" size="30"><br>
   File 3: <input type="file" name="file3" size="30"><br>
   File 4: <input type="file" name="file4" size="30"><br><br>
           <input type="submit" value="Upload">
   </form>
   </font></p>
   </body>
   </html>

   <%
}
%>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.