A lil update script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Monotoko
Forum Commoner
Posts: 64
Joined: Fri Oct 26, 2007 4:24 pm

A lil update script

Post 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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: A lil update script

Post by jackpf »

Yes.

Some useful functions maybe:

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

Stuff like that.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: A lil update script

Post 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.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: A lil update script

Post 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:
Post Reply