PDA

View Full Version : Adding text to text file as uploading?


viobear
03-07-2005, 01:44 PM
Alrite, i want to make a site where visitors have a chance to upload a text file, so #1, how do I make an upload thing that filters everything but .txt files??

#2 As the file is uploading I want to add text to the bottom of the file, this text:
www.example.com dd-mm-yyyy

Of course dd-mm-yyyy being the date the file was uploaded, and then i want to move this text file to a directory..

How can i do this, thnx in advanced!

devinemke
03-07-2005, 03:06 PM
you should read the manual section on Handling file uploads (http://www.php.net/manual/en/features.file-upload.php). to check the filetype you could something like:

if ($_FILES['userfile']['type'] != 'text/plain')
{
// display error
exit();
}

once the file is uploaded and moved to whatever directory you want, you can append whatever text you want using:
fopen (http://www.php.net/fopen)
fwrite (http://www.php.net/fwrite)

bcarl314
03-07-2005, 03:09 PM
Not only that, you can use the file functions to get the name of the file, date created and last modified dates as well. Not sure if you need to "add" anything to the file itself.