Moving and Renaming Files

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
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Moving and Renaming Files

Post by Gen-ik »

Is it possible to move and rename .txt files using PHP?
I can't for the life of me work out how to do it :roll:

Thanks.
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

you can move and rename *any* files with php. you can create, modify, or delete any file to which you have permissions. you want to check out the filesystem reference to see what to do. Good luck, and if you have trouble, feel free to ask us for help. But please - give it a good try before you ask. remember, php.net is your friend!
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post by MattF »

A simple way of doing it would be to open the old one, copy it's contents and then write it to one with a different name or in a different folder. That would copy or rename/copy. But you'd still have the original lying about the place.
Beefy
Forum Newbie
Posts: 6
Joined: Wed Aug 14, 2002 5:06 am

Post by Beefy »

At first you should check the file permissions with the fileperms/fileowner/...-functions. You can't write a file, if you haven't the permissions to do so.

You can copy a file with the copy-function and you can rename a file with the rename-function (quite simple to remember ;) :)). You can delete a file with the unlink function (works under unix-systems and under windows since php4, I think).


mfg, Beefy.
Post Reply