Jump to content

Copy folder problem...


bobcooper

Recommended Posts

Hi there,

 

I am having a problem copying a folder and its sub folders. When I try the script on my computer it works fine, but when I upload it to my website it only creates a new folder, it does not copy the files. I was thinking it might be something to do with permissions so added chmod settings but that does not work either.

 

Here is the code:

 

<?php


$dir = "../";
$count = 0;

if(is_dir($dir)) {
if($handle = opendir($dir)) {
	while(($file = readdir($handle)) !== false) {
		if($file != '.' && $file != '..' && $file != 'upload'){ 
			$count++;
		}
	}
	closedir($handle);
}
}
$issueNo = $count + 1;
$destination = $_SERVER['DOCUMENT_ROOT']."/newsletter/issue_".$issueNo;
$source = $_SERVER['DOCUMENT_ROOT']."/newsletter/issue_1";

function full_copy( $source, $target ) {
if ( is_dir( $source ) ) {
	@mkdir( $target );
	chmod($target, 0777);
	$d = dir( $source );
	while ( FALSE !== ( $entry = $d->read() ) ) {
		if ( $entry == '.' || $entry == '..' ) {
			continue;
		}
		$Entry = $source . '/' . $entry; 
		if ( is_dir( $Entry ) ) {
			full_copy( $Entry, $target . '/' . $entry );
			continue;
		}
		copy( $Entry, $target . '/' . $entry );
	}

	$d->close();
}else {
	copy( $source, $target );
}
}

full_copy($source, $destination);

?>

 

Your help would be greatly appreciated,

 

Thanks,

 

Bob

www.bobcooper.org.uk

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.