Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 790345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:40:03+00:00 2026-05-14T21:40:03+00:00

I am using windows, Mysql DB, PHP I am building the Joomla Component whose

  • 0

I am using windows, Mysql DB, PHP

I am building the Joomla Component whose one of the functionality is to synchronize the folders
I want to sync two folders of different name.. How can I do this? It has to be dne in the same machine, no two different servers are involved in it..

How to sync two folders in PHP?

UPDATED

IN Context of Alex Reply

What if i am editing any .jpg file in one folder and saving it with same name as it has, also this file is already present in other folder. And I want this edited pic to be transfered to the other folder.? also I have Joomla’s nested file structured to be compared

UPDATE 2

I have a recursive function which will output me the complete structure of folder… if u can just use it to concat ur solution in…

<?
function getDirectory($path = '.', $ignore = '') {
    $dirTree = array ();
    $dirTreeTemp = array ();
    $ignore[] = '.';
    $ignore[] = '..';

    $dh = @opendir($path);

    while (false !== ($file = readdir($dh))) {

        if (!in_array($file, $ignore)) {
            if (!is_dir("$path/$file")) {
                $stat = stat("$path/$file");
                $statdir = stat("$path");
                $dirTree["$path"][] = $file. " === ". date('Y-m-d H:i:s', $stat['mtime']) . " Directory == ".$path."===". date('Y-m-d H:i:s', $statdir['mtime']) ;

            } else {

                $dirTreeTemp = getDirectory("$path/$file", $ignore);
                if (is_array($dirTreeTemp))$dirTree = array_merge($dirTree, $dirTreeTemp);
            }
        }
    }
    closedir($dh);

    return $dirTree;
}


$ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini', '.ftpquota');

$dirTree = getDirectory('.', $ignore);
?>
<pre>
    <?
    print_r($dirTree);
    ?>
</pre> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:40:03+00:00Added an answer on May 14, 2026 at 9:40 pm

    I just ran this, and it seems to work

    function sync() {
    
        $files = array();
        $folders = func_get_args();
    
        if (empty($folders)) {
            return FALSE;
        }
    
        // Get all files
        foreach($folders as $key => $folder) {
            // Normalise folder strings to remove trailing slash
            $folders[$key] = rtrim($folder, DIRECTORY_SEPARATOR);   
            $files += glob($folder . DIRECTORY_SEPARATOR . '*');    
        }
    
        // Drop same files
        $uniqueFiles = array();
        foreach($files as $file) {
            $hash = md5_file($file);
    
            if ( ! in_array($hash, $uniqueFiles)) {
                $uniqueFiles[$file] = $hash; 
            }
        }
    
    
        // Copy all these unique files into every folder
        foreach($folders as $folder) {
            foreach($uniqueFiles as $file => $hash) {
                    copy($file, $folder . DIRECTORY_SEPARATOR . basename($file));
            }
        }
        return TRUE;    
    }
    
    // usage
    
    sync('sync', 'sync2');
    

    You simply give it a list of folders to sync, and it will sync all files. It will attempt to skip files that appear the same (i.e. of whom their hash collides).

    This however does not take into account last modified dates or anything. You will have to modify itself to do that. It should be pretty simple, look into filemtime().

    Also, sorry if the code sucks. I had a go at making it recursive, but I failed 🙁

    For a one way copy, try this

    $source = '/path/to/source/';
    $destination = 'path/to/destination/';
    
    $sourceFiles = glob($source . '*');
    
    foreach($sourceFiles as $file) {
    
        $baseFile = basename($file);
    
        if (file_exists($destination . $baseFile)) {
    
            $originalHash = md5_file($file);
            $destinationHash = md5_file($destination . $baseFile);
            if ($originalHash === $destinationHash) {
                continue;
            }
    
        }
        copy($file, $destination . $baseFile);
    }
    

    It sounds like you just want to copy all files from one folder to another. The second example will do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 430k
  • Answers 430k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Possible Duplicate (when tagged with Flash) How can I record… May 15, 2026 at 1:58 pm
  • Editorial Team
    Editorial Team added an answer Use a java.awt.image.BufferedImage BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);… May 15, 2026 at 1:58 pm
  • Editorial Team
    Editorial Team added an answer I currently use GeSHi Filter for syntax highlighting for my… May 15, 2026 at 1:58 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.