Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to copy documents?
#1
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

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!!
Reply


Messages In This Thread
How to copy documents? - by michbukana - 02-09-2012, 04:11 PM

Forum Jump:


Users browsing this thread: