Re: Creating a text file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/18/07, Ryan Lao <ryan@xxxxxxxxxxxxxxxxxxx> wrote:
Thanks for your reply, I want to create individual text files for every form
submitted.



""Daniel Brown"" <parasane@xxxxxxxxx> wrote in message
news:<ab5568160707180514p29eb9c34qdb3c1f2edad0a6c2@xxxxxxxxxxxxxx>...
> On 7/17/07, Ryan Lao <ryan@xxxxxxxxxxxxxxxxxxx> wrote:
> > 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 text
file
> > when it is submitted. The text file will contain the users complete
name,
> > the filename that was being uploaded and the additional comments from
the
> > user. 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.php
> >
> >
>
>     Ryan,
>
>     Are you trying to create individual files for each form
> submission, 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



   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) {
       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 by
the 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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux