Click to See Complete Forum and Search --> : Writing data fron index.php to NEW.txt


DJsAC
01-14-2004, 10:08 AM
I would like to Write the names of files to a txt file after they are uploaded with this script: if ($_POST['submit'])
{
$name = $_FILES['File']['name'];
$tmpname = $_FILES['File']['tmp_name'];
$size = $_FILES['File']['size'];

if (copy ($tmpname, "$uploaddir/$name"))
{
print ("Bestandsnaam: $name<br/><br/>\n");
print ("Bestandsgrote: $size<br/><br/>\n");
print ("Het bestand is geupload!<br/><br/>\n");
}
else
{
print ("Het bestand kon niet worden geupload.");
}
$fp = fopen("NEW.txt","a");
flock($fp,2);
fputs($fp,"$uploaddir/$name|\n");
flock($fp,3);
fclose($fp);
chmod("NEW.txt",0777);
unlink ($tmpname);
}
?> <hr>
Upload a file here:
<form action="index.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td width=100 height="26" valign="Middle">BESTAND:</td>
<td width=250 height="26" valign="Middle"><input type="file" name="File" size="20"></td>
</tr>
<tr>
<td width=100 height="26" valign="Middle">VAK:</td>
<td width=100 height="26" valign="Middle"><select name="uploaddir">
<option value="NL" selected>NL</option>
<option value="GS">GS</option>
<option value="GL">GL</option>
<option value="CK">CKV</option>
<option value="ETC">Other</option>
</select></td>
</tr>
<tr>
<td valign="middle" colspan="2" align="left"><input type="submit" name="submit" value="Upload Bestand"></td>
</tr>
</table>
The text file is called NEW.txt and will be read bij this piece of code:$fp = fopen("NEW.txt","r");
while(!feof($fp))
{
$buffer = fgets($fp,50000);
$buffer = trim($buffer);
$NEW = $NEW.$buffer;
}
fclose($fp);

list($New01,$New02,$New03,$New04,$New05,$New06,$New07,$New08,$New09,$New10,$New11,$New12,$New13,$New 14,$New15,$New16,$New17,$New18,$New19,$New20) = split("\|",$NEW,20);
The catch is that I would like for the filename to be written at the top of the txt file. so that the upper 10 files are also the newest ones. I know that there is a really simple solution, but i just couldn't think of it.

DJsAC
01-15-2004, 05:26 PM
Could someone please help?:(

pyro
01-15-2004, 05:36 PM
Either read the filr to a string, and prepend your new data before writing it back, or use fseek to move the file pointer...

DJsAC
01-16-2004, 01:32 AM
Ok, thanks Pyro,
I'll try that. If I have any questions you'll be hearing from me again.:)