tags:

views:

41

answers:

3

How to process files inside the folder sub directories using php script. Actually I want the image files inside each sub directories residing in my server itself to process and save to another location and save the folder name & file name in the database. Can anyone help and give a sample script on how to operate this...

the folder structure may be something like this

parent folder
 sub-folder1
   img1
   img2
   img3
   .
   .
   img'n'
 sub-folder2
   img1
   img2
   img3
   .
   .
   img'n'
 sub-folder3
   img1
   img2
   img3
   .
   .
   img'n'
 .
 .
 .
 sub-folder'n'

Also if on the process of copying and writing to database how can show a progress bar

thanks in advance

A: 

This is described in detail at http://php.net/manual/en/features.file-upload.php. You can store files anywhere you want.

stillstanding
+1  A: 

u can use this function to copy a folder including its subfolders from source to target.

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

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

inside the loop u can execute a query to save file names to the database.

rahim asgari
steven_desu
how can I show a progress bar when the process continues...
Rahul TS
here is a tutorial: http://www.ibm.com/developerworks/library/os-php-v525/index.html
rahim asgari
A: 

You can use PHP glob() to gather your files. Saving info to the database is pretty straight forward. Moving the files can be done via rename(). The MySQLi documentation is full of examples on how to talk to your database.

Gipetto