Page 1 of 1

Moving and Renaming Files

Posted: Tue Aug 13, 2002 2:46 pm
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.

Posted: Tue Aug 13, 2002 3:55 pm
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!

Posted: Wed Aug 14, 2002 2:00 am
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.

Posted: Wed Aug 14, 2002 5:06 am
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.