Read files from directory and copy / move to another directory using php


<?php

/* For wordress */
$upload_dir = wp_upload_dir();
$dir = $upload_dir[‘basedir’].”/2015/11/”;
$dest_dir = $upload_dir[‘basedir’].”/developer/”;

/* For PHP */
$dir = “/source”;
$dest_dir = “/destination/”;

if (is_dir($dir)){
if ($dh = opendir($dir)){ $i=1; $cou = 0;
while (($file = readdir($dh)) !== false){
if (( $file != ‘.’ ) && ( $file != ‘..’ )) {
/* Copy files */
copy($dir . $file,$dest_dir . $file);
$i++;
/* Move files */
rename($dir . ‘/’ . $file, $dest_dir . ‘/’ . $file);
}

}
closedir($dh);
}
}
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s