SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    deleting text files

    say guys.. i have a code that inputs text to a text file:

    PHP Code:
    // write to file
                    
    $textfile fopen ("C:/instructions.txt""w+");
                    
    fwrite($textfile$fp);
                    
    fclose ($textfile); 
                    echo 
    "<P><B>Your instructions have been updated into the database!</B></P>"
    Now, how do I have a command that deletes this text file, or at least flushes/erases the text back to NULL?

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2000
    Location
    Bangkok,Thailand
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    unlink it

    You can use the unlink() function.
    Here is an example I lifted from the PHP manual:
    <?php
    $delete = unlink("C:\\directory\\filename.extension");
    if($delete){
    echo "Succesfully deleted";
    }else{
    echo "Could not delete";
    }
    ?>
    You can fine more examples here:
    http://www.php.net/manual/en/function.unlink.php

    Hope this helps

    Stuart
    http://www.travelfish.org

  3. #3
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cool.. thanks!

  4. #4
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm.. how about i don't want to delete the file... but simply to erase the file's contents?

    I tried using

    PHP Code:
    $textfile fopen ("C:/instructions.txt""w+"); 
    but it seems you need to type in stuff to overwrite it, instead of erasing the contents straightout....

  5. #5
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    PHP Code:
    $textfile fopen ("C:/instructions.txt""w");
    fwrite(""$fp);
    fclose ($textfile); 
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  6. #6
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah.. this idea hit me too before i got the mail notification...

    thanks anyway!


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
  •