01-04-2010 05:38 PM
// Include the required Alfresco PHP API objects
require_once 'Alfresco/Service/WebService/WebServiceFactory.php';
require_once 'Alfresco/Service/Repository.php';
require_once 'Alfresco/Service/SpacesStore.php';
require_once "Alfresco/Service/Session.php";
$timestamp = time();
// Specify the connection details
// this works:
//$repositoryURL = "http://localhost:8080/alfresco/api";
//$userName = "admin";
//$password = "admin";
// this doesn't work, node is created, but node content is empty
$repositoryURL = "https://<windows remote machine>:8443/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);
$nodes = $session->query($spacesStore, "PATH:\"app:company_home\"");
$contentNode = $nodes[0];
//create new file
$file_name = $_FILES['uploadedfile']['name'] . " (" . $timestamp . ")";
$file_tmp = $_FILES['uploadedfile']['tmp_name'];
$file_type = $_FILES['uploadedfile']['type'];
$file_size = $_FILES['uploadedfile']['size'];
$upload = $contentNode->createChild('cm_content', 'cm_contains', $file_name);
$contentData = new ContentData($upload, "cm:content");
$contentData->mimetype = $file_type;
$upload->cm_name = $file_name;
$upload->cm_description = 'Test File Description';
$contentData->size = $file_size;
$contentData->encoding = 'UTF-8';
$contentData->writeContentFromFile($file_tmp);
$upload->cm_content = $contentData;
echo "Content set<br>";
try {
$session->save();
echo "Saved changes to " . $upload->getId() . "<br>";
} catch (Exception $e) {
echo 'Caught exception: ';
print_r($e);
}
06-07-2010 04:53 PM
<html>
<head></head>
<body>
<form enctype="multipart/form-data" action="uploadContent01.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
<?php
$parantID="0dbd52a9-2d80-4e85-8e41-7bb03be90bed";
$repoURL = "http://alfrescourl/alfresco/api";
$userName = "admin";
$password = "password";
$repository = new Repository($repoURL);
$ticket = $repository->authenticate($userName,$password);
$session = $repository->createSession($ticket);
$spacesStore = new SpacesStore($session);
$companyHome = $spacestore->companyHome;
$currentNode = null;
$currentNode=$session->getNode($spacesStore,$parantID);
$upload = $currentNode->createChild('cm_content', 'cm_contains', 'cm_'.$_FILES['uploadedfile']['name']);
$pathFile = $_FILES['uploadedfile']['tmp_name'];
$content_data = new ContentData($upload, $property, $mimetype, $encoding);
$content_data->mimetype = $_FILES['uploadedfile']['type'];
$content_data->encoding = "UTF-8";
$content_data->writeContentFromFile($pathFile);
$upload->cm_content = $content_data;
$upload->cm_name = $_FILES['uploadedfile']['name'];
echo $upload->cm_name;
$session->save();
?>
07-08-2017 09:42 AM
what is parantID ?? why it is used ? can you please me
06-08-2010 05:03 AM
// Create new node
$newNode = $contentNode->createChild('cm_content', 'cm_contains', "Hui_Buh__$timestamp");
// Create contentdata from some file
$contentData = new AlfContentData($newNode, '{http://www.alfresco.org/model/content/1.0}content');
$contentData->setMimetype('application/pdf');
$contentData->setEncoding ('UTF-8');
$contentData->writeContentFromFile('4046.pdf');
// Set the properties on node
$props = $newNode->getProperties();
$props['{http://www.alfresco.org/model/content/1.0}content'] = $contentData;
$props['{http://www.alfresco.org/model/content/1.0}name'] = "Hui Buh (" . $timestamp . ").pdf";
$props['{http://www.alfresco.org/model/content/1.0}description'] = 'Ein doofer Test';
$props['{http://www.alfresco.org/model/content/1.0}title'] = 'Alles ueber Hui Buh';
$newNode->setProperties($props);
// Save it all
$session->save(false);
06-08-2010 01:40 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.