View Full Version : PHP Text Files...

12-15-2007, 01:47 AM
I am working with a form and submitting it through a php file.

When the form is submitted the php sends an email to the submitted email address, and to the administrator's email address. It also writes the message to a text file.

As of now, I have this set up so that it writes each submission to the same file....however, I would like to be able to have the php write the submission to a different file each time...based off of their inputted username for instance.

Here is the code I have:

$date=date("D F d Y");

$inputString = "$time, $date\n\n$username has applied for a staff position.\n\nHere is the information sumitted:\n\nUSERNAME: $username\n\nEMAIL: $email\n\nAPPLYING FOR: $job\n\nNUMBER OF POSTS: $posts\n\nINFO: $why\n\n$approved\n\nIP ADDRESS: $ip\n\n====================================\n\n";

$fp = fopen( $file , "a" );

fwrite( $fp, $inputString );

fclose( $fp );

$message2="$username,\nThank you for submitting your application!\nThe Administrators of the board shall review your application and get back to you in due course.\n\nThe following is your submitted information:\nUSERNAME: $username\nEMAIL: $email\nAPPLYING FOR: $job\nNUMBER OF POSTS: $posts\nINFO: $why\n**\n$approved\n**\nThanks again,\n The Global Forums Team\n\n------------\nThis is an automated message, please don't reply!";

$message="Global Forums Administrators,\nThe following is a pending staff application.\n---------------\n\nUSERNAME: $username\n\nEMAIL: $email\n\nAPPLYING FOR: $job\n\nNUMBER OF POSTS: $posts\n\nINFO: $why\n\n$approved\n\nIP ADDRESS: $ip\n\nSubmission Logged: **URL REMOVED**\n===============================\nCopy of Submitted email:\n----\n$message2";

mail($to,"GF Staff Application",$message,"From: $email");

mail($email,"GF Staff Application Submission",$message2,"From: $to");

header( "Location: **URL REMOVED**");

Is there anyway to create a new text file for each submission and name it according to their username?

12-15-2007, 02:08 AM

$file="staffapp.txt"; sets the file. Use something else.

You could use a timestamp with time(), or $_POST['username'], etc.

Then change the fopen line to:
$fp = fopen( $file , 'w+' );

12-15-2007, 02:16 AM
I have tried this in multiple formats...with no success.

Could you perhaps give me the exact format I would use to name it with a timestamp...I like that idea.

$file=time()".txt" or something....I don't know how to get the ".txt" extension on the file.

12-15-2007, 02:29 AM
To merge two strings, you need to use a dot character.

$file = time().'.txt';

12-15-2007, 02:35 AM
oh...duh I should have known that...

Thank you soooo much for all of your help!