earn easy 50 credits (yopic-php copy)

Status
Not open for further replies.

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
i have a directory called "config" in my public_html dirctory i want a script where i can copy the whole "config" directory with all its files to a new directory(config_copy) in the public_html directory

iam doing this cause iam tryin to make a site where all the users content is placed in their directory....this is to avoid messing up stuff

i succeeded in coping many files at once but not the whole dirctory ..........ive seen many people doin it but i dont know how ..........if u make a script for me ill pay you 50 c.

if you want to refer you can check this..... http://in2.php.net/copy
 
Last edited:

Tariqul Islam

New Member
Messages
182
Reaction score
0
Points
0
PHP:
  <?php

// A function to copy files from one directory to another one, including subdirectories and
// nonexisting or newer files. Function returns number of files copied.
// This function is PHP implementation of Windows xcopy  A:\dir1\* B:\dir2 /D /E /F /H /R /Y
// Syntaxis: [$number =] dircopy($sourcedirectory, $destinationdirectory [, $verbose]);
// Example: $num = dircopy('A:\dir1', 'B:\dir2', 1);

function dircopy($srcdir, $dstdir, $verbose = false) {
  $num = 0;
  if(!is_dir($dstdir)) mkdir($dstdir);
  if($curdir = opendir($srcdir)) {
    while($file = readdir($curdir)) {
      if($file != '.' && $file != '..') {
        $srcfile = $srcdir . '\\' . $file;
        $dstfile = $dstdir . '\\' . $file;
        if(is_file($srcfile)) {
          if(is_file($dstfile)) $ow = filemtime($srcfile) - filemtime($dstfile); else $ow = 1;
          if($ow > 0) {
            if($verbose) echo "Copying '$srcfile' to '$dstfile'...";
            if(copy($srcfile, $dstfile)) {
              touch($dstfile, filemtime($srcfile)); $num++;
              if($verbose) echo "OK\n";
            }
            else echo "Error: File '$srcfile' could not be copied!\n";
          }                   
        }
        else if(is_dir($srcfile)) {
          $num += dircopy($srcfile, $dstfile, $verbose);
        }
      }
    }
    closedir($curdir);
  }
  return $num;
}

$num = dircopy('./', './../config_backup', 1);

echo "$num files copied!";
?>

This will work fine. Just create a file in your config directory and paste the above code. Then open the file using your browser and domain.

example: http://your_site_url/your_file_name.php

That's all.
 
Last edited:

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
no it aint workin its only creating a folder called config_backup ....and not a single file is copied and also when i run the php script i get this message"o files copied"

iam not copying the folders for backup to be more specific ......when a user registers into my site with a username "xyz" i want the 'config" folder to be copied and named as 'xyz' ie the username in which he registers


i want all the files and subfolders to be copied
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
PHP:
function scopy($dirsource, $dirdest)
{ 
if(is_dir($dirsource))$dir_handle=opendir($dirsource);
mkdir($dirdest."/".$dirsource, 0750);
while($file=readdir($dir_handle))
{
if($file!="." && $file!="..")
{
if(!is_dir($dirsource."/".$file)) copy ($dirsource."/".$file, $dirdest."/".$dirsource."/".$file);
else COPY_RECURSIVE_DIRS($dirsource."/".$file, $dirdest);
}
}
closedir($dir_handle);
return true;
}

Try this instead.
 

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
i really dont understand php
all i want is something like this abn input box called with name "xyz" and when user hits the submit button the directory "config" which is a directory present in public_html must be copied to "xyz" with all files and folders
 
Status
Not open for further replies.
Top