I have a Folder in that i have sub folders like excel_files, excel_files_backup , images etc and files like excel2.php , get_mail.php etc .
In excel_files folder having excel files
and excel_files_backup is an empty folder .

iam uploading excel files in excel_files folder to database after inserting iam unlinking the files in excel_files. so the excel_files folder become empty after inserting data into database. and iam downloading new files from mail and dumping into excel_file folder so every time the folder will become empty after inserting into database and when new mail received the file will downloaded to excel_file folder.

now my need is i want to copy excel files in excel_files folder to excel_files_backup by using php script. so that every time when i run the excel2.php the files in the excel_files should be copied into excel_files_folder and then inserted to database and then excel_files folder get deleted.


please give me suggestion(script) for doing this.

Here's a function I found on php.net that will copy the directory. I have also added an unlink code to delete the original folder after copy. This may throw a permission denied error or it may work. Good luck!

<?php
$folder = 'excel_files';
$backup = 'excel_files_backup';
full_copy($folder, $backup);
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 );
            }
           unlink($source);
            $d->close();
        }
		else
        {
            copy( $source, $target );
        }
    }

?>

thank u buddy working fine with this code but showing warnings like this.

Warning: copy(excel_files_backup/.svn/all-wcprops) [function.copy]: failed to open stream: Permission denied

Warning: copy(excel_files_backup/.svn/entries) [function.copy]: failed to open stream:

Warning: copy(excel_files_backup/.svn/format) [function.copy]: failed to open stream:

i tried it now it is showing this warning even working my requirement fine.

Warning: copy() [function.copy]: The first argument to copy() function cannot be a directory.

tell me how can i rectify this warning.

Thanks All.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.