How to copy documents? - michbukana - 02-09-2012
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!!
RE: How to copy documents? - steinm - 02-10-2012
(02-09-2012, 04:11 PM)michbukana Wrote: 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.
You should use LetoDMS_Folder::addDocument(). It has a parameter for the filename of the document. The file is copied not moved. So, you could as well use the filename of any document already in the DMS.
Uwe
RE: How to copy documents? - michbukana - 02-10-2012
Thanks for the answer,
I try to use the Folder::addDocument function but an error ocurred. I don't know how to use this function, param $dest is the folder to add the new copy file and param $document, the file to copy.
$_tmpFile value is incorrect.
In the function call I write:
PHP Code: $res = $dest->addDocument($_fileName, '', 0, 'Administrator', '', $_tmpFile, $_originalName, $_fileType, $_mimeType, $_sequence, $reviewers=array(), $approvers=array(),$_reqversion,$version_comment='');
Complete code:
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); } // Get document to copy properties $latestContent = $document->getLatestContent(); $_fileName = $document->getName(); $_fileType = $latestContent->getFileType(); $_mimeType = $latestContent->getMimeType(); $_originalName = $latestContent->getOriginalFileName(); $_sequence = $document->getSequence(); $_reqversion = $latestContent->getVersion(); $_tmpFile = $latestContent->getFolderPathPlain(); // I don't know how to get the tmpFile ???? // Copy only photos (jpg,gif,png) if($_fileType == ".jpg" || $_fileType == ".gif" || $_fileType == '.png'){ $res = $dest->addDocument($_fileName, '', 0, 'Administrator', '', $_tmpFile, $_originalName, $_fileType, $_mimeType, $_sequence, $reviewers=array(), $approvers=array(),$_reqversion,$version_comment=''); }
print "<li>"; print "<li>".$document->getName().' ** archivo copiado correctamente'.$document->getID(); print "</li>"; }
Excuse me for my english
RE: How to copy documents? - steinm - 02-10-2012
(02-10-2012, 03:45 PM)michbukana Wrote: Thanks for the answer,
I try to use the Folder::addDocument function but an error ocurred. I don't know how to use this function, param $dest is the folder to add the new copy file and param $document, the file to copy.
$_tmpFile value is incorrect.
In the function call I write:
PHP Code: $res = $dest->addDocument($_fileName, '', 0, 'Administrator', '', $_tmpFile, $_originalName, $_fileType, $_mimeType, $_sequence, $reviewers=array(), $approvers=array(),$_reqversion,$version_comment='');
You should have a look at the function addDocument() in the source. The owner is not string but a user object.
Uwe
RE: How to copy documents? - michbukana - 02-12-2012
First, Thanks very much for help me but I can´t copy documents, I try with this:
PHP Code: // Get document to copy properties $latestContent = $document->getLatestContent(); $_fileName = $document->getName(); $_fileType = $latestContent->getFileType(); $_mimeType = $latestContent->getMimeType(); $_originalName = $latestContent->getOriginalFileName(); $_sequence = $document->getSequence(); $_reqversion = $latestContent->getVersion(); $_tmpFile = $latestContent->getPath(); // I don't know how to get the tmpFile ???? $_user = $latestContent->getUser(); // Copy only photos (jpg,gif,png) if($_fileType == ".jpg" || $_fileType == ".gif" || $_fileType == '.png'){ $res = $dest->addDocument($_fileName, '', 0, $_user, '', $_tmpFile, $_originalName, $_fileType, $_mimeType, $_sequence, $reviewers=array(), $approvers=array(), $_reqversion, $version_comment=''); }
I think that this source is wrong, I need a string with the path but I do anything wrong when I get the document´s properties.
PHP Code: $_tmpFile = $latestContent->getPath();
I try to test addDocument and documents add to the new copy folder but the path is incorrect, the problem is the $_tmpFile I don´t know how to get the value correctly.
RE: How to copy documents? - steinm - 02-13-2012
(02-12-2012, 03:12 PM)michbukana Wrote: I try to test addDocument and documents add to the new copy folder but the path is incorrect, the problem is the $_tmpFile I don´t know how to get the value correctly.
echo the path to the document and check if it makes sense.
Uwe
|