Pepiijn,
I've just finished creating a file upload script that writes to a text log file when the person uploads the file.
The file get's uploaded to the designated NT web server directory and creates a directory with the user's lastname and copies the file into that directory. Then it appends to a log file with the Date, Username, directory uploaded to, filename, filesize, and time.
For not being that great of a programming it seems to work real well. I found all the code I needed here on PHPBuilder web site. However, It took a lot of trial and error and much time to re-search. Hopefully this will help all who view it.
Here is the Upload.HTM file:
<head><title>FileUPLOAD</title></head><body>
<form method="post" action="upload.php" enctype="multipart/form-data">
<div align="center">
<center>
<table border="0" cellspacing="1" width="100%">
<tr>
<td width="100%" colspan="2"><b><font face="Tahoma" size="4" color="#800000">File
Upload Program:</font></b>
<p> </td>
</tr>
<tr>
<td width="25%"><font face="Tahoma" color="#800000"><b>First Name:</b></font></td>
<td width="75%"><input type="text" name="FirstName" size="20"></td>
</tr>
<tr>
<td width="25%"><font face="Tahoma" color="#800000"><b>Last Name:</b></font></td>
<td width="75%"><input type="text" name="LastName" size="20"></td>
</tr>
<tr>
<td width="25%"><font face="Tahoma" color="#800000"><b>Phone
Number:</b></font></td>
<td width="75%"><input type="text" name="Phone" size="20"></td>
</tr>
<tr>
<td width="100%" colspan="2"><br>
Select Up to 6 files to Upload:</td>
</tr>
<tr>
<td width="25%"><font face="Tahoma" size="3"><b>
File 1.</b></font></td>
<td width="75%"> <input name="userfile[]1" type="file"> </td>
</tr>
<tr>
<td width="25%"><font face="Tahoma" size="3"><b>
File 2. </b></font></td>
<td width="75%"> <input name="userfile[]2" type="file"> </td>
</tr>
<tr>
<td width="25%"><font face="Tahoma" size="3"><b>
File 3. </b></font></td>
<td width="75%"> <input name="userfile[]3" type="file"> </td>
</tr>
<tr>
<td width="25%"><font face="Tahoma" size="3"><b>
File 4. </b></font></td>
<td width="75%"> <input name="userfile[]4" type="file"> </td>
</tr>
<tr>
<td width="25%"><font face="Tahoma" size="3"><b>
File 5. </b></font></td>
<td width="75%"> <input name="userfile[]5" type="file"> </td>
</tr>
<tr>
<td width="25%"><font face="Tahoma" size="3"><b>File 6. </b></font></td>
<td width="75%"> <input name="userfile[]" type="file"> </td>
</tr>
<tr>
<td width="25%"></td>
<td width="75%"></td>
</tr>
</table>
</center>
</div>
<p>
<input type="submit" value="Upload!!!" >
</form>
Here is the Upload.asp Script:
<?
set_time_limit(120);
for($i=0;$i<sizeof($userfile);$i++)
{
if(!$userfile_size[$i])
continue;
$MyDir = "c:/inetpub/wwwroot/test/$LastName//";
if (file_exists($myDir));
@mkdir ($MyDir, 0700);
$UPLOAD = fopen( $userfile[$i], "r" );
$contents = fread( $UPLOAD,$userfile_size[$i]);
fclose( $UPLOAD );
$SAVEFILE = fopen($MyDir.$userfile_name[$i], "wb" );
fwrite( $SAVEFILE, $contents,$userfile_size[$i] );
fclose( $SAVEFILE );
$Today = date("m.d.y"); // 05.17.01
$Time = date("H:i:s"); // 14:12:43
$file = "c:/inetpub/wwwroot/Uploads/log.txt";
$Line = "---------------------------------------------------------------------------------------";
$p=fopen($file, "a");
$line = fgets($p,filesize($file));
fwrite($p, "$Today\040");
fwrite($p, "$FirstName\040");
fwrite($p, "$LastName\040");
fwrite($p, "$MyDir\040");
fwrite($p, "$userfile_name[$i]\040");
fwrite($p, "$userfile_size[$i]\040bytes\040");
fwrite($p, "$Time\r\n");
fwrite($p, "$Line\r\n");
fclose($p);
}
$Date = print (date ("l dS of F Y h:i:s A\r\n"));
echo ", Submission of your file has been Receive by the server!\r\n";
?>
I haven't had time to make it pretty but I thought this would help everybody trying to make a file upload script work and then try making it log to a file.
Your PHP.ini file on your web server is defaulted to 2 megs. If you want to upload bigger files then you will need to change the default.
Shoot me an email and let me know if works for you.