Re: Creating a text file
| From: | Daniel Brown | Date: | Thu, 19 Jul 2007 13:33:04 +0000 |
| Subject: | Re: Creating a text file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-259173@lists.php.net to get a copy of this message | ||
On 7/18/07, Ryan Lao <ryan@activediscovery.net> wrote:
Thanks for your reply, I want to create individual text files for every form submitted. ""Daniel Brown"" <parasane@gmail.com> wrote in message news:<ab5568160707180514p29eb9c34qdb3c1f2edad0a6c2@mail.gmail.com>... On 7/17/07, Ryan Lao <ryan@activediscovery.net> wrote:Ryan, Please keep your replies on the list so that others may benefit as well. Here's a very, very simple example that will handle individual, unique file creation each time the form is submitted: <? if($_POST) {i made a simple PHP form that would ask for the users complete name, a button that would browse to a file that the user wants to upload, a text area for additional comments, and a submit button. This form works just fine. what i want to achieve next is for my form to also create a textfilewhen it is submitted. The text file will contain the users completename,the filename that was being uploaded and the additional comments fromtheuser. Can anyone give me some ideas on how to do this? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpRyan,Are you trying to create individual files for each formsubmission, or one file that will be appended with new data upon submission? -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107
extract($_POST);
/* Do your file upload routine first, as you have it now.
Then just grab the name of the file that was uploaded
and place it into a variable named $uploadfile. */
$filedir = "records"; // This directory should be writable bythe script.
$filename = date("YmdHis")."_".$firstname."_".$lastname.".txt";
$thefile = $filedir."/".$filename;
$handle = fopen($thefile,"w+"); // The w+ will write to a
file, or create it if it's not there.
$contents = "Name:\t\t".$firstname." ".$lastname."\n";
$contents .= "File:\t\t".$uploadfile."\n"; // This line and
the one above have two tabs to keep in line
$contents .= "Comments:\t".$usercomments;
fwrite($handle,stripslashes($contents));
fclose($handle);
echo "File written successfully!";
exit;
}
?>
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>"
enctype="multipart/form-data">
First Name: <input type="text" name="firstname"><BR />
Last Name: <input type="text" name="lastname"><BR />
File: <input type="file" name="uploadfile"><BR />
Comments: <textarea rows="3" cols="18"
name="usercomments"></textarea><BR />
<input type="submit" value="Send Form"></form> -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107