Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: How to overwrite?

  1. #11
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Do you mean you need some of the script code?
    No. He means he needs all of it.
    Also, could the file to write to being a .txt be a problem?
    No.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  2. #12
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok, here is the full code:
    PHP Code:
    <?php
    $filename 
    "sitename.txt"// file to write to

    $error "An error occured while changing the site name!";

    $success "Site name changed, redirecting...";



        
    // Change Name
    $name stripslashes($_POST['name']);
        
        
    // Change URL 
    if ($sitelink stripslashes($_POST['sitelink'])) {
        
    $add "
    <!-- Site Name -->
    <a href="
    .$sitelink.">".$name."</a>
    "
    ;

    $sitename = @file_get_contents($filename).$add;
        

        
    $file = @fopen($filename"w+");
        @
    fwrite($file$sitename);
        @
    fclose($file);
        
    $message $success;
          }
        else {
        
    $message $error;
        }
    echo 
    "
    <html>
    <head>
    <title>Change Site Name</title>
    <meta http-equiv=\"refresh\" content=\"2;url=changetitles.php\">
    "
    .$message."
    </head>
    <body>
    </body>
    </html>"
    ;

    ?>

  3. #13
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    PHP Code:
    $sitename = @file_get_contents($filename).$add
    This line is causing it to append the contents instead of overwriting it. If you want the file overwritten replace the above code with this.
    PHP Code:
    $sitename $add
    If you want it to append remove
    PHP Code:
    $sitename = @file_get_contents($filename).$add
    and replace
    PHP Code:
    $file fopen($filename"w"); 
    with
    PHP Code:
    $file fopen($filename,'a'); 

  4. #14
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks a ton, i got it all working now

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •