today i was wondering if it would be possible to copy directories or file using php code..

well, you're in luck because yes it is possible.


How To Copy File



Example Script CODE:
<?php
$file = 'old_file.txt';
$newfile = 'new_file.txt';

if (!copy($file, $newfile)) {
echo "failed to copy $file...n";
}
?>


you can get more info at:
http://www.php.net/manual/en/function.copy.php

How to copy Directory

to copy directory you can use this handy function:

function full_copy( $source, $target ) {
	if ( is_dir( $source ) ) {
		@mkdir( $target );
		$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 );
	}
}


you can call this function with this example, lets say i want to copy my themes from my source files to my new websites i would do this:

PHP CODE
$source ='/var/www/source/theme';
$destination = '/var/www/newsite/theme/';
full_copy($source, $destination)