El siguiente es el código PHP para cargar archivos usando Alfresco Web Service. Pongo algunos comentarios dentro del código. Si hay algo que te confunda, deja tu comentario y espero poder ayudarte.
if (isset($_SERVER["ALF_AVAILABLE"]) == false)
{
require_once "./alfresco_sdk/remote/Alfresco/Service/Repository.php";
require_once "./alfresco_sdk/remote/Alfresco/Service/Session.php";
require_once "./alfresco_sdk/remote/Alfresco/Service/SpacesStore.php";
require_once "./alfresco_sdk/remote/Alfresco/Service/ContentData.php";
}
$repositoryUrl = "http://localhost:8080/alfresco/api";
$userName = "admin";
$password = "admin";
// Authenticate the user and create a session
$repository = new Repository($repositoryUrl);
$ticket = $repository->authenticate($userName, $password);
$session = $repository->createSession($ticket);
// Create a reference to the 'SpacesStore'
$spacesStore = new SpacesStore($session);
$dir_name = "s".$irbID;
// Use a serach to get the guest home space we will use to place the new content in
$nodes = $session->query($spacesStore, "PATH:"app:company_home/cm:testing/cm:$dir_name"");
if(!empty($nodes)){
echo "good, no need to do anything.";
}else{
$nodes = $session->query($spacesStore, "PATH:"app:company_home/cm:testing"");
$contentNode = $nodes[0];
$newSpace = $contentNode->createChild('cm_folder', 'cm_contains', 'cm_'.$dir_name);//here has to be cm_ as it is here.
$newSpace->cm_name = $dir_name;
$newSpace->cm_title = "This is a title";
$newSpace->cm_description = 'Description of Space';
$session->save();
unset($session);
$session = $repository->createSession($ticket);
$nodes = $session->query($spacesStore, "PATH:"app:company_home/cm:testing/cm:$dir_name"");
}
$guestHome = $nodes[0];
// Get the name of the new node
$name = $_POST['txt_docs_title'];
$contentNode = $guestHome->createChild("cm_content", "cm_contains", "cm_".$name);//!!the folder's name has to begin with 'cm_' otherwise, using web service can not find it later.
$contentNode->addAspect("cm_titled");
// Set the name, title and description property values
$contentNode->cm_name = $name;
$contentNode->cm_title = $_POST['num_ct_ID'];
$contentNode->cm_description = "testing description --program creek";
// Set the content onto the standard content property for nodes of type cm:content.
// We are going to assume the mimetype and encoding for ease
$contentData = $contentNode->updateContent("cm_content", $_FILES['document']['type'], "UTF-8");
// Set the content to be the content file uploaded from the client
$contentData->writeContentFromFile($_FILES["document"]["tmp_name"]);
// Save the new node
$session->save();
|
if (isset ($ _ SERVIDOR[«ALF_AVAILABLE»]) == falso) {require_once «./alfresco_sdk/remote/Alfresco/Service/Repository.php»; require_once «./alfresco_sdk/remote/Alfresco/Service/Session.php»; require_once «./alfresco_sdk/remote/Alfresco/Service/SpacesStore.php»; require_once «./alfresco_sdk/remote/Alfresco/Service/ContentData.php»; } $ repositoryUrl = «http: // localhost: 8080 / alfresco / api»; $ userName = «admin»; $ contraseña = «admin»; // Autentica al usuario y crea una sesión $ repository = new Repository ($ repositoryUrl); $ ticket = $ repositorio-> autenticar ($ nombre de usuario, $ contraseña); $ sesión = $ repositorio-> createSession ($ ticket); // Crea una referencia al ‘SpacesStore’ $ spacesStore = new SpacesStore ($ sesión); $ dir_name = «s». $ irbID; // Use una búsqueda para obtener el espacio de la casa de invitados que usaremos para colocar el nuevo contenido en $ nodes = $ session-> query ($ spacesStore, «PATH: » app: company_home / cm: testing / cm: $ dir_name «»); if (! empty ($ nodes)) {echo «bien, no es necesario hacer nada»; } else {$ nodos = $ sesión-> consulta ($ spacesStore, «RUTA: » aplicación: inicio_empresa / cm: prueba «»); $ contentNode = $ nodos[0]; $ newSpace = $ contentNode-> createChild (‘cm_folder’, ‘cm_contains’, ‘cm _’. $ dir_name); // aquí tiene que ser cm_ como está aquí. $ newSpace-> cm_name = $ dir_name; $ newSpace-> cm_title = «Este es un título»; $ newSpace-> cm_description = ‘Descripción del espacio’; $ sesión-> guardar (); desarmado ($ sesión); $ sesión = $ repositorio-> createSession ($ ticket); $ nodos = $ sesión-> consulta ($ spacesStore, «RUTA: » aplicación: inicio_empresa / cm: prueba / cm: $ nombre_directorio «»); } $ guestHome = $ nodos[0]; // Obtener el nombre del nuevo nodo $ name = $ _POST[‘txt_docs_title’]; $ contentNode = $ guestHome-> createChild («cm_content», «cm_contains», «cm _». $ name); // !! el nombre de la carpeta debe comenzar con ‘cm_’ de lo contrario, el uso del servicio web no puede encontrarlo más tarde. $ contentNode-> addAspect («cm_titled»); // Establecer los valores de propiedad de nombre, título y descripción $ contentNode-> cm_name = $ name; $ contentNode-> cm_title = $ _POST[‘num_ct_ID’]; $ contentNode-> cm_description = «descripción de la prueba –program creek»; // Establezca el contenido en la propiedad de contenido estándar para nodos de tipo cm: contenido. // Vamos a asumir el mimetype y la codificación para mayor facilidad $ contentData = $ contentNode-> updateContent («cm_content», $ _FILES[‘document’][‘type’], «UTF-8»); // Establezca el contenido para que sea el archivo de contenido cargado desde el cliente $ contentData-> writeContentFromFile ($ _ FILES[«document»][«tmp_name»]); // Guarde el nuevo nodo $ session-> save ();