Jump to content

Recommended Posts

soo.. how do I do it?

copy only copies ONE file...

 

I want to copy a folder, subfolder, files, and subfiles.  I don't care about attributes.

I thought about making the folder a zip, and then using extract but that was confusing and took too long on the server.

 

so what do I do?  Is there a script that will parse the dir and COPY all the files?

Link to comment
https://forums.phpfreaks.com/topic/64663-copy-folder/
Share on other sites

unction COPY_RECURSIVE_DIRS($dirsource, $dirdest)
{ // recursive function to copy
// all subdirectories and contents:
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;
}

Link to comment
https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322393
Share on other sites

This will probably help..

 

      function copyr($source, $dest){
      // Simple copy for a file
      if (is_file($source)) {
      $c = copy($source, $dest);
      chmod($dest, 0777);
      return $c;
      }
      // Make destination directory
      if (!is_dir($dest)) {
      $oldumask = umask(0);
      mkdir($dest, 0777);
      umask($oldumask);
      }
      // Loop through the folder
      $dir = dir($source);
      while (false !== $entry = $dir->read()) {
      // Skip pointers
      if ($entry == ‘.’ || $entry == ‘..’) {
      continue;
      }
       
      // Deep copy directories
      if ($dest !== “$source/$entry”) {
      copyr(”$source/$entry”, “$dest/$entry”);
      }
      }
       
      // Clean up
      $dir->close();
      return true;
      }

Link to comment
https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322398
Share on other sites

YAY!! thank you..

 

I will try it before I say if its solved or not...

 

$d = "C:/Inetpub/wwroot/" . $_CUSTOMER['path'] . "/forum";
$s = "C:/Inetpub/installers/forum";
COPY_RECURSIVE_DIRS($s,$d);

function COPY_RECURSIVE_DIRS($dirsource, $dirdest)
{ // recursive function to copy
// all subdirectories and contents:
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;
}

Link to comment
https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322401
Share on other sites

Problem:

 

no matter how I do a full path it wont take it because of the special uses of \...

 

$filename = "C:/Inetpub\wwwroot\";
$filename = $filename . $p;
$filename = $filename . "\forum\includes\config.php";

give me:

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\Inetpub\wwwroot\* on line 36

Parse error: syntax error, unexpected T_STRING in C:\Inetpub\wwwroot\* on line 36

Link to comment
https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322420
Share on other sites

lol then I get a different erorr, tried that.

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Inetpub\wwwroot\Registration\vbcreate.php on line 38

 

It doenst expect the $p variable cause the first line:

$filename = "C:/Inetpub/wwwroot/";

doesnt close if I have a / and then a quote.  The / denotes to escape the " -,-.

 

Got any other suggestions?

Link to comment
https://forums.phpfreaks.com/topic/64663-copy-folder/#findComment-322431
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.