Delete the contents of a file

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

nick_k
New php-forum User
New php-forum User
Posts: 34
Joined: Wed Dec 25, 2002 6:04 am
Location: The Netherlands
Contact:

Delete the contents of a file

Postby nick_k » Wed Dec 25, 2002 7:02 am

i just made my first guestbook in php, witch stores all the input in a file. what i want to make, is a administrative function, that allows the person with a valid password to clear all the comments. so basically, what i need is a function that deletes all the contents of a specific file.
Thanks, Nick

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Wed Dec 25, 2002 7:15 am

part of code that you can use

Code: Select all

if ($login == "login" && $password == '$password')
{
// your administrate functions
}


this is basis for your admin script

nick_k
New php-forum User
New php-forum User
Posts: 34
Joined: Wed Dec 25, 2002 6:04 am
Location: The Netherlands
Contact:

Postby nick_k » Wed Dec 25, 2002 7:50 am

thanks, now i got the basis, but does anyone know how to delete all the contents of a certain file?


btw. Pejone, which part of Ukraine are you from?

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Thu Dec 26, 2002 4:44 am

You can rewrite all file. you can use this script (copyright be Kompadre
from PHP forum at http://www.flasher.ru/forum/)

Code: Select all

<?

$fh = fopen ("file", "r");
while ($line = fgets($fh, 1024)) {
if (!ereg("pattern", $line)) $out = $out . $line;
}
fclose ($fh);

$fh = fopen ("file", "w");
fwrite ($fh, $out);
fclose ($fh);

?>




P.S.
I am from Khmelnitsky, Western part of Ukraine. Why You asking ?

nick_k
New php-forum User
New php-forum User
Posts: 34
Joined: Wed Dec 25, 2002 6:04 am
Location: The Netherlands
Contact:

Postby nick_k » Thu Dec 26, 2002 5:24 am

thanks, thats just what i was looking for.

P.S.

I was just asking because my mom is also from Ukraine

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Thu Dec 26, 2002 5:28 am

Do you speak ukrainian or russian ?

nick_k
New php-forum User
New php-forum User
Posts: 34
Joined: Wed Dec 25, 2002 6:04 am
Location: The Netherlands
Contact:

Postby nick_k » Thu Dec 26, 2002 7:33 am

i speak russian fluently

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Thu Dec 26, 2002 7:35 am

do you have ICQ ?

nick_k
New php-forum User
New php-forum User
Posts: 34
Joined: Wed Dec 25, 2002 6:04 am
Location: The Netherlands
Contact:

Postby nick_k » Thu Dec 26, 2002 9:37 am

yep, 178707273


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest