1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

rename the text files in numbers, eg. 1,2,3....

Discussion in 'Web Development' started by ted_chou12, Dec 9, 2006.

  1. ted_chou12

    ted_chou12 New Member

    Joined:
    Nov 21, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    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:
    <?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?
     
  2. ted_chou12

    ted_chou12 New Member

    Joined:
    Nov 21, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    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
     
  3. ted_chou12

    ted_chou12 New Member

    Joined:
    Nov 21, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    absolutely no one can help me out with this? :( :( :(
     
  4. ted_chou12

    ted_chou12 New Member

    Joined:
    Nov 21, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    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?
     
  5. ted_chou12

    ted_chou12 New Member

    Joined:
    Nov 21, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    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:
    <?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!
     
  6. ted_chou12

    ted_chou12 New Member

    Joined:
    Nov 21, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    can anyone give me a hand here...?
     
  7. ted_chou12

    ted_chou12 New Member

    Joined:
    Nov 21, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    nobody can help me???
     
  8. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Keep a counter a counter file which will keep the track of the last number, using which you can create files in sequence.
     
  9. ted_chou12

    ted_chou12 New Member

    Joined:
    Nov 21, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    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!
     
  10. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    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);

    ?>
     
  11. ted_chou12

    ted_chou12 New Member

    Joined:
    Nov 21, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
  12. ted_chou12

    ted_chou12 New Member

    Joined:
    Nov 21, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    but what does this symbol: @file mean?
     
  13. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    file() is a function, and the @ sign will prevent PHP from generating any warnins/errors!
     
  14. ted_chou12

    ted_chou12 New Member

    Joined:
    Nov 21, 2006
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    I see, thanks for being so helpful btw!
     

Share This Page