tags:

views:

145

answers:

2

I have a folder named "repository" in my admin folders. This folder holds 2 files: index.html and content.php. When a user creates a new page the php creates a new folder specified by the user then will need to copy the two files into that folder while leaving them in the repository.

copy(file,dest) does not work. rename(file,dest) moves the files to the new folder but I lose them in the repository.

How do I copy the files in one folder to the new folder without losing the files in the original folder?

$dest = '../'.$menuLocation.'/'.$pageName; 
$file1= "repository/index.html"; 
$file2= "repository/content.php"; 
mkdir($dest,0777); 
rename($file1,$dest.'/index.html'); 
rename($file2,$dest.'/content.php');

$menuLocation and $pageName are supplied by the user. The files are there, file_exists returns back true. Also, the directory is created with no issues. rename() also works I just lose the files in repository.

A: 

Use copy(). Make sure you capture the return value so that your program knows if it worked or not. Also check permission of the files and directory to confirm that the user executing the PHP script is able to create the new file in the place you specified. You might want use is_writable() on the directory to confirm these assumptions.

Clutch
A: 

For anyone hunting for the solution to this:

when using copy() in php you also need to include the file name.

copy(orginalfile,destination_with_filename);

for example:

wrong:

copy('/temp/sports/basketball.jpg','/images/sports/')

Correct:

copy('/temp/sports/basketball.jpg','/images/sports/basketball.jpg')
dcp3450