Page 1 of 1

A lil update script

Posted: Sat Aug 22, 2009 3:07 pm
by Monotoko
Hellos :)
I need to make a simple update script, what i need this script to do is:

when a user runs the script, i need it to go to the www directry, i then need it to search inside each directry for "pubster.txt"
Once it finds a directry with a pubster.txt, it needs to find index.php in that directry, delete the last 4 lines of it, and add a new part to the bottom.

Would that be possible? Because i cannot figure out a way around it

A jab in the right direction or some functions/scripts may be of help :)

~Thank you

Re: A lil update script

Posted: Sat Aug 22, 2009 3:18 pm
by jackpf
Yes.

Some useful functions maybe:

glob()
file_exists()
fopen()
fwrite()

Stuff like that.

Re: A lil update script

Posted: Sat Aug 22, 2009 3:20 pm
by requinix
Sounds like this is the wrong solution to some problem you have.

You can use glob to get a list of files in a directory; is_file, is_dir, and file_exists should be self-explanatory; file to get an array of lines from a file; array_pop to remove the last element from an array; implode to convert an array into a string; and fopen+fwrite+fclose (or file_put_contents on PHP 5) to write to a file.

Re: A lil update script

Posted: Sat Aug 22, 2009 3:22 pm
by Darhazer
Start with opendir and closedir
Then file_exists
Then fopen, fclose, fread, fwrite
You can check my post here for tip how to implement removing of the lines: