Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Web Development (http://www.go4expert.com/forums/web-development-forum/)
-   -   rename the text files in numbers, eg. 1,2,3.... (http://www.go4expert.com/forums/rename-text-files-eg-123-t2180/)

ted_chou12 9Dec2006 21:44

rename the text files in numbers, eg. 1,2,3....
 
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, 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,

PHP Code:

<?php
$dataf 
"1.txt";
$file fopen("$dataf","w");
$write fwrite($file,"not important text");
fclose($file);
?>

What code do I insert in if i want to rename the $dataf text file in numbers, eg. 1,2,3... in sequence, each time creating a new file with a interger above the last one?

ted_chou12 10Dec2006 13:12

Re: rename the text files in numbers, eg. 1,2,3....
 
can anyone help me with this please? I am having a hard time figuring it out, if you have any confusion with my wordings, just reply to this.
Thanks

ted_chou12 10Dec2006 15:42

Re: rename the text files in numbers, eg. 1,2,3....
 
absolutely no one can help me out with this? :( :( :(

ted_chou12 10Dec2006 16:05

Re: rename the text files in numbers, eg. 1,2,3....
 
sorry for posting it twice, but because I couldnt find my first post so I reposted my question again, but could anyone help me with this?

ted_chou12 10Dec2006 16:07

Re: rename the text files in numbers, eg. 1,2,3....
 
here is what I already got to so far, but there seems to be an error with this, can anyone have a look at this:
PHP Code:

<?php
if(isset($_POST['Submit']))
{
?><table width="100%" border="0" cellspacing="1" bordercolor="#000000" bgcolor="#333333">
  <tr>
    <td width="432" bgcolor="#FFFFFF"><?php
//here is what i wish you to have a look at*************
while (file_exists($filea)) {
    
$category $_POST['category'];
    
$filea "$category/topic.txt";
    
$counter_var 0;
    
$counter_var ++;
    
$filea $category."/topic".$counter_var.".txt";

} else {

$topic $_POST['topic'];
$category $_POST['category'];
$message $_POST['message'];
$datetime date("m/d/y h:i a");

$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");
$topic stripslashes($topic);
$message stripslashes($message);
$message ereg_replace("\n""<BR>\n"$message);

if (
$message != "" && $category !="" && $topic !="") {$file fopen($filea,"a");
$write fwrite($file,"$topic#$datetime#$name#$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 bgcolor="#FAEBD7">
<tr bgcolor="#E0FFFF" align=center width="100%"><td></td><td align=left bgcolor="#FAEBD7"><font size=5><b>Post New Thread:</b></font></td></tr>
<form name="newtopic" action="" method="post">
<tr bgcolor="#E0FFFF" align=center width="100%"><td valign=top align=left><b>Topic:</b></td><td align=left bgcolor="#FAEBD7"><input name="topic" type="text" id="topic" style="font-family: Arial"></td></tr>
<tr bgcolor="#E0FFFF" align=center width="100%"><td valign=top align=left><b>Category:</b></td><td align=left bgcolor="#FAEBD7"><select name="catagory" size="1">
<option value="homework">Homework</option><option value="arts">Arts/Musical</option><option value="sports">Sports</option><option value="technologies">Technologies</option><option value="social">Socializing</option><option value="news">Current Events</option><option value="others">Others</option><option value="about">Web Help</option></select></td></tr>
<tr bgcolor="#E0FFFF" align=center width="100%"><td valign=top align=left><b>Post Content:</b></td><td align=left bgcolor="#FAEBD7">
<textarea name="message" id="message" rows="6" cols="57" style="font-family: Arial"></textarea></td></tr>
<tr bgcolor="#E0FFFF" align=center width="100%"><td></td><td align=left bgcolor="#FAEBD7"><input type="submit" name="Submit" value="Submit"><input type="reset" name="Reset" value="Reset"></td></tr>
</form>
</table>

Thankyou for your time!

ted_chou12 10Dec2006 17:38

Re: rename the text files in numbers, eg. 1,2,3....
 
can anyone give me a hand here...?

ted_chou12 11Dec2006 13:53

Re: rename the text files in numbers, eg. 1,2,3....
 
nobody can help me???

pradeep 11Dec2006 15:51

Re: rename the text files in numbers, eg. 1,2,3....
 
Keep a counter a counter file which will keep the track of the last number, using which you can create files in sequence.

ted_chou12 11Dec2006 17:19

Re: rename the text files in numbers, eg. 1,2,3....
 
can you teach me how to do the ++ thing with the txt file then? I just want a very brief tutorial on the counter thing, thank you so much for replying!

pradeep 11Dec2006 17:46

Re: rename the text files in numbers, eg. 1,2,3....
 
Code: PHP

<?
$counterFile = "counter.txt";

$count = @file($counterFile);
$count = trim(implode("",$count));
$count++

$h = fopen($counterFile,'w');
fwrite($h,$count);
fclose($h);

$h = fopen("file$count.txt",'w');
// put in your data
fclose($h);

?>



All times are GMT +5.5. The time now is 03:22.