02-09-2012, 04:11 PM 
(This post was last modified: 02-09-2012, 04:14 PM by michbukana.)
		
	
	
		Hi,
I try to make a functions to copy folders and documents, folders copy correctly but I´dont know how to copy a file and add to the new folder copy.
My code;
Copy folder code
Copy document code, I don't know how to finish it
Call function
Thanks very much for the hard work!!
	
	
	
	
I try to make a functions to copy folders and documents, folders copy correctly but I´dont know how to copy a file and add to the new folder copy.
My code;
Copy folder code
PHP Code:
<?php
function copyFolder($folder,$first,$dest) {    
    if($first != 0){
        $copyText = '_copia';
    }else{
        $copyText = '';
    }    
    
    $subFolders = $folder->getSubFolders();
    $documents = $folder->getDocuments();
    
    $name = $folder->getName().$copyText;
    $comment = $folder->getComment();
    $user = $folder->getOwner();
    $sequence = $folder->getSequence();
    $machineStatus = $folder->getMachineStatus();
    $historic = $folder->getHistoric();
    $parentFolder = $folder->getParent();
    
    if($dest == null){
        $copyFolder = $parentFolder->addSubFolder($name, $comment, $user, $sequence, $machineStatus, $historic);
    }else{
        $copyFolder = $dest->addSubFolder($name, $comment, $user, $sequence, $machineStatus, $historic);
    }
    
    print "<li>".$folder->getName().' ** directorio copiado correctamente';
    print "<ul>";
    
    foreach ($subFolders as $sub){
        copyFolder($sub,0,$copyFolder);
    }
    
    foreach ($documents as $document){
        copyDocument($document,$copyFolder);
    }
    print "</ul>";
    print "</li>";
} 
Copy document code, I don't know how to finish it
PHP Code:
function copyDocument($document,$dest) {
    if (file_exists($dms->contentDir.$document->getDir())) {
        $handle = opendir($dms->contentDir.$document->getDir());
        while ($entry = readdir($handle) ) {
            if (is_dir($dms->contentDir.$document->getDir().$entry)) continue;
            else{
                $folder_size += filesize($dms->contentDir.$document->getDir().$entry);
            }
        }
        closedir($handle);
    }
    
    $latestContent = $document->getLatestContent();
    $fileName = $document->getName();
    $fileType = $latestContent->getFileType();
    $mimeType = $latestContent->getMimeType();
    $originalName = $latestContent->getOriginalFileName();
    $userfiletype = '.jpg';
    
    echo "<br/><br/><br/>Folder: ".$dms->contentDir.$document->getDir();
    
    $documentID = $document->getID();
    
    // Copy only photos (jpg,gif,png)
    if($fileType == ".jpg" || $fileType == ".gif" || $fileType == '.png'){
        echo "****************************** IMAGE COPIED ******************************";
               
               //**************** I DON'T KNOW HOW TO COPY AND ADD A DOCUMENT *******************;
    }
    print "<li>";
    print "<li>".$document->getName().' ** archivo copiado correctamente'.$document->getID();
    print "</li>";
}
// End copy code
?>Call function
PHP Code:
<?php
<?php
// Call function
echo "Copiando ...<br/>";
echo "<ul>";
copyFolder($folder,1,null);
echo "</ul>";
?>Thanks very much for the hard work!!

 
 

 

