Jump to content

how to rename texts created from php form to accending numbered.


ted_chou12

Recommended Posts

You will need to loop through all files in a given directory, then use the rename() function to rename the files - each time the loop goes round increment a counter variable:

$counter_var = 1;

//begin loop

$newname = $originalfile . "" . $counter_var; 
rename("$originalfile","$newname");
$counter_var++;

//end loop
Link to comment
Share on other sites

sorry, but does anyone know how to get this into the fwrite() function?
what i want to do is when the visitor fills out the form and press submit, i want to store the information as a text file (in an empty directory),  and call it "text1.txt", when the second visitor comes and submit another form, I want the second form to call "text2.txt", and so on....  continues to name it in accending numbers, below is my code:
[code]
<?
if(isset($_POST['Submit']))
{
?><table width="100%" border="0" cellspacing="1" bordercolor="#000000" bgcolor="#333333">
  <tr>
    <td width="432" bgcolor="#FFFFFF"><?

$recipients = $_POST['recipients'];
$dataf = "$recipients/messages/message.txt";
$subject = $_POST['subject'];
$message = $_POST['message'];
$datetime = date("m/d/y h:i a");

if (file_exists("$recipients")) {
   echo "";
} else {echo "No such username! Please double check your recipient's username!";}

$username = $_SESSION['username'];
$bData = @file("log_files/$username.txt"); // collect all data into an array
foreach($bData as $v){list($name,$email,$gender,$birthm,$birthd,$birthy,$location,$modfiytime) = explode("#",$v);}

//word censors
include("censor.txt");
$subject = stripslashes($subject);
$message = stripslashes($message);
$message = ereg_replace("\n", "<BR>\n", $message);
$dataf = "$recipients/messages/message.txt";

if ($message != "" && $recipients !="" && $subject !="") {$file = fopen("$dataf","w");
$write = fwrite($file,"$name#$subject#$datetime#$message");fclose($file);}
else
{echo"Required field(s) left blank!<br>";}

if($write == TRUE)
{echo"Message successfully pasted!";}
else
{echo"Sorry but there was an error posting your message!";}
?></td>
  </tr>
</table><? } ?>
<br>
<table>
<form name="message" action="" method="post">
<tr><td valign=top><b>To:</b></td><td><input name="recipients" type="text" id="recipients" style="font-family: Arial"></td></tr>
<tr><td valign=top><b>Subject:</b></td><td><input name="subject" type="text" id="subject" style="font-family: Arial"></td></tr>
<tr><td valign=top><b>Message:</b></td><td>
<textarea name="message" id="message" rows="6" cols="57" style="font-family: Arial"></textarea></td></tr>
<td></td><td><input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset"></td>
</form>
</table>
[/code]
can anyone help me to put the two together? thanks a lot :D
Link to comment
Share on other sites

ted, DEMANDING help in such a fashion will get you absolutely nowhere. the people on this site donate their time for free. In addition, most of the help you've currently been after shows ABSOLUTELY NO SIGN that you've tried to help yourself - but rather you EXPECT others to write the scripts for you.

I for one would rather help someone with a little more patience. You may want to read the [url=http://www.phpfreaks.com/forums/index.php/topic,6264.0.html]forum posting guidelines[/url], as you're on a one-man mission to break most of the rules an etiquette.

[move]the manual is your friend, go and read it[/move]
Link to comment
Share on other sites

ted, please wait a bit longer before bumping your thread.  Also, if you have a secondary question, you'd be better off to start a new thread.

EDIT: That's not funny.  Keep being smart and this thread will be closed.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.