cancel
Showing results for 
Search instead for 
Did you mean: 

PHP-Upload Skript

sf_urzl
Champ in-the-making
Champ in-the-making
Hello everyone,

i'm searching for an working examples for uploading files via php into alfresco repo (version 3.2).
The examples i've found in wiki did'nt work. So it would be a good idea to update the documentation from time to time… :?

Can anyone help me?

Thank you so much!

Regards,
SF
5 REPLIES 5

ddanninger
Champ in-the-making
Champ in-the-making
Hi,

here is a example its little dirty but it works 😃

<?php
    require_once "Alfresco/Service/Repository.php";
   
    require_once "Alfresco/Service/Session.php";
    require_once "Alfresco/Service/SpacesStore.php";

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

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

    $spacesStore = new SpacesStore($session);

    $companyHome = $spacesStore->companyHome;                    
?>

<html>
<head>
   <title>Upload</title>
</head>

<body>
<?php
    if (isset($_POST["Submit"])) {
       $fileName = $_FILES['uploadFile']['name'];
       $fileType = $_FILES['uploadFile']['type'];
      
       $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($_FILES['uploadFile']["tmp_name"]);
      
       $session->save();

       echo "Uploaded!";
    }
    else { ?>
        <form action="" method="post" enctype="multipart/form-data">
        <input type="file" name="uploadFile">
        <input type="submit" value="Upload" name="Submit">
        </form>
   <?php }  ?>
             

</body>

</html>

Hopefully i could help you.

Best Regards
Dominik

sf_urzl
Champ in-the-making
Champ in-the-making
Thank you, but i get another error. I can upload a file, the file is also shown in Alfresco, but the file ist empty!
Know anybody the problem?

Regards, SF

mounty
Champ in-the-making
Champ in-the-making
xxxx

ddanninger
Champ in-the-making
Champ in-the-making
Thank you, but i get another error. I can upload a file, the file is also shown in Alfresco, but the file ist empty!
Know anybody the problem?

Regards, SF

what kind of error?

lukmansiregar
Champ in-the-making
Champ in-the-making
Thank you, but i get another error. I can upload a file, the file is also shown in Alfresco, but the file ist empty!
Know anybody the problem?

Regards, SF


i got the same problem. the file is empty, with 0KB. And when download the file from alfresco, come this error

The node's content is missing:
   node: workspace://SpacesStore/18280bf9-7065-4b61-8192-1b8d5da5cca2
   reader: null 
Please contact your system administrator.

Can anyone know the problem?