ted_chou12 Posted December 7, 2006 Share Posted December 7, 2006 I wish to know how to rename the files with some i++ functions, like when writing to a text file, i want to name the text files in sequence eg. the first file "file 1",second "file 2"...etc and so on, does anyone know how to do that? :D Quote Link to comment https://forums.phpfreaks.com/topic/29823-how-to-rename-texts-created-from-php-form-to-accending-numbered/ Share on other sites More sharing options...
matto Posted December 7, 2006 Share Posted December 7, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/29823-how-to-rename-texts-created-from-php-form-to-accending-numbered/#findComment-137181 Share on other sites More sharing options...
ted_chou12 Posted December 8, 2006 Author Share Posted December 8, 2006 oh thanks! :) Quote Link to comment https://forums.phpfreaks.com/topic/29823-how-to-rename-texts-created-from-php-form-to-accending-numbered/#findComment-137411 Share on other sites More sharing options...
ted_chou12 Posted December 8, 2006 Author Share Posted December 8, 2006 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 arrayforeach($bData as $v){list($name,$email,$gender,$birthm,$birthd,$birthy,$location,$modfiytime) = explode("#",$v);}//word censorsinclude("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 Quote Link to comment https://forums.phpfreaks.com/topic/29823-how-to-rename-texts-created-from-php-form-to-accending-numbered/#findComment-137493 Share on other sites More sharing options...
redbullmarky Posted December 8, 2006 Share Posted December 8, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/29823-how-to-rename-texts-created-from-php-form-to-accending-numbered/#findComment-137543 Share on other sites More sharing options...
ted_chou12 Posted December 8, 2006 Author Share Posted December 8, 2006 ... ??? Quote Link to comment https://forums.phpfreaks.com/topic/29823-how-to-rename-texts-created-from-php-form-to-accending-numbered/#findComment-137544 Share on other sites More sharing options...
ted_chou12 Posted December 8, 2006 Author Share Posted December 8, 2006 okay, ive read it. Quote Link to comment https://forums.phpfreaks.com/topic/29823-how-to-rename-texts-created-from-php-form-to-accending-numbered/#findComment-137545 Share on other sites More sharing options...
ober Posted December 8, 2006 Share Posted December 8, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/29823-how-to-rename-texts-created-from-php-form-to-accending-numbered/#findComment-137547 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.