Copying Files In A Directory

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
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Copying Files In A Directory

Post by andylyon87 »

How do I go about copying a file to another folder say from a dir called "form_data" to a dir called "moderated". Both these folders are within a folder called "test". I want files to move from the "form_data" folder to the "moderator" folder.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

rename('test/form_data/file1.txt', 'test/moderated/file1.txt');

This will 'move' it by the way, not sure if you want to copy or move as you mention both ;) If you want to copy then see http://php.net/copy
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

To move a file could i use a function that copies the file to the second folder and deletes it from the first folder
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Yeah, that's what http://php.net/rename does
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

sorry just realised :)
Post Reply