AnsweredAssumed Answered

Uploading a file in alfresco server using PHP

Question asked by gmasand09 on Jul 6, 2017

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

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

$repositoryUrl = "http://localhost:8080/share/page";
$userName = "admin";
$password = "****";
$parentID="2a113503-7ed5-4d8f-ad3f-9f96e20f054b";


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

$store=new SpacesStore($mysession);
$node=$mysession->getNode($store,$parantID);
$upload=$node->createChild('cm_content','cm_contains',"$fname");
//$contentData=new ContentData($upload,"{http://www.alfresco.org/model/content/1.0}content");
$contentData=new ContentData($upload,'{http://http://www.alfresco.org/model/content/1.0}content');


?>

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

<body>
<?php
$fname = $_FILES['uploadFile']['name'];
if (isset($_POST["Submit"])) {
$fname=$_FILES['uploadFile']['name'];
$ftmp=$_FILES['uploadFile']['tmp_name'];
$ftype=$_FILES['uploadFile']['type'];
$fsize=$_FILES['uploadFile']['size'];

$contentData->encoding = 'UTF-8';
$contentData->writeContentFromFile($ftmp);
$contentData->size = $fsize;
$contentData->mimetype = $ftype;
$upload->cm_name = $fname;
$upload->cm_description = 'File Description';
$upload->cm_content = $contentData;
echo "ContentData = ".$contentData."<br>";
$mysession->save();
echo "done";
}
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>

 

 

This is my PHP file i dont knw what it says and what to do with this file. 
How to run this file . 

Where to execute ?

can somebody explain me this please ??

Outcomes