AnsweredAssumed Answered

Document upload with PHP

Question asked by philippe07 on Aug 25, 2011
Latest reply on Nov 29, 2012 by philippe07
Dear All,

At first thanks for taking time to read my message !

I've played around with ifresco PHP Library (great !!) and Alfresco 3.4. I arrive to upload document to companyhome. Now i would like to change to a specific SpaceStore BUT i don't arrive to find a way to do this (This one : workspace://SpacesStore/9c32b505-e69a-4e29-a857-874c27163ab6)

My code following :

function alfresco_upload($file)
{
        if (!file_exists($file))
        {
                echo $file;
                die('Pb de fichier');
        }

        $root_classes = '/home/XXX/LIBRARIES/';
        require_once $root_classes . "Alfresco/Service/WebService/AlfrescoWebService.php";
        require_once $root_classes . "Alfresco/Service/Repository.php";

        require_once $root_classes . "Alfresco/Service/Session.php";
        require_once $root_classes . "Alfresco/Service/SpacesStore.php";

        $repositoryUrl = "http://XXXX/alfresco/api";
        $userName = "admin";
        $password = "XXXX";



        $repository = new Repository($repositoryUrl);
        $ticket = $repository->authenticate($userName, $password);
        $session = $repository->createSession($ticket);

        $spacesStore = new SpacesStore($session);

        $companyHome = $spacesStore->companyHome;

        $fileName = basename($file);
        $finfo = finfo_open(FILEINFO_MIME,"/usr/share/misc/magic");
        $fileType = finfo_file($finfo,$file);
        finfo_close($finfo);

        $HomePath = "app_company_home";

        $contentNode = $companyHome->createChild("cm_content", "cm_contains", $HomePath);

        $contentNode->cm_name = $fileName;
        $contentNode->cm_title = "Title";
        $contentNode->cm_description = "Description";

        $contentData = $contentNode->setContent("cm_content", $fileType, "UTF-8");

        $contentData->writeContentFromFile($file);

        $session->save();

        echo $file . ' uploaded !' . "\r\n";
}

?>

Is anyone have some clue about doing this ?

Thanks for your reading,

Regards

Philippe

Outcomes