Upload content using php api

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2007 09:51 AM
I couldn't find how can i upload file using the php API ?
can you please help ?
10x
- Labels:
-
Archive

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2007 07:07 AM
I'm going to add some tutorials/examples to the Wiki.
I'll be sure to show how to upload content and will post here once its available.
Cheers,
Roy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2007 07:42 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2007 11:19 AM
I've got a really simple example done now. I just need to update the Wiki with some supporting documentation.
Should be available next week,
Cheers,
Roy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 08:48 AM
I'm posting it so it may be helpfull:
//Repository URL$alfURL="http://xcm:80/alfresco/api";//User$alfUser="";$alfPassword="";//ID of the PARANT FOLDER$parantID="f93f665c-508b-11dc-800c-d5564c95a581";$fname=$_FILES['ALF']['name'];$ftmp=$_FILES['ALF']['tmp_name'];$ftype=$_FILES['ALF']['type'];// Create the session$repository = new Repository($alfURL);$ticket = $repository->authenticate($alfUser, $alfPassword);$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=$upload->cm_content;$contentData->mimetype = $ftype;$upload->cm_name="$fname";$contentData->encoding = "UTF-8";$contentData->writeContentFromFile("$ftmp");$upload->cm_content=$contentData;$mysession->save();echo "done";

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2008 09:19 AM
Fatal error: Uncaught exception 'Exception' with message 'A mime type for the content property {http://www.alfresco.org/model/content/1.0}content on node workspace://SpacesStore/sessionTICKET_6f1b6246bdcaee4e18b233349170ae8239e3bcac0 must be set' in /home/manish/alfresco-php-library/Alfresco/Service/ContentData.php:197 Stack trace: #0 /home/manish/alfresco-php-library/Alfresco/Service/Node.php(604): ContentData->onBeforeSave(Array, Array) #1 /home/manish/alfresco-php-library/Alfresco/Service/Session.php(156): Node->onBeforeSave(Array) #2 /home/manish/alfresco-php-library/Examples/fileUpload.php(35): Session->save() #3 {main} thrown in /home/manish/alfresco-php-library/Alfresco/Service/ContentData.php on line 197
=============
The actual script executed that i executed was ( verbatim)
<?php
require_once('Alfresco/Service/Repository.php');
require_once('Alfresco/Service/Session.php');
require_once('Alfresco/Service/SpacesStore.php');
//require_once('../config.php');
$alfURL="http://localhost:8080/alfresco/api";
//User
$alfUser="admin";
$alfPassword="admin";
//ID of the PARENT FOLDER
$parantID="67910128-d484-11dc-ad55-9fdf34d87024";
$fname=$_FILES['ALF']['name'];
$ftmp=$_FILES['ALF']['tmp_name'];
$ftype=$_FILES['ALF']['type'];
// Create the session
$repository = new Repository($alfURL);
$ticket = $repository->authenticate($alfUser, $alfPassword);
$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=$upload->cm_content;
$contentData->mimetype = $ftype;
$upload->cm_name="$fname";
$contentData->encoding = "UTF-8";
$contentData->writeContentFromFile("$ftmp");
$upload->cm_content=$contentData;
$mysession->save();
echo "done";
?>
==============
Could you please help me out here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2008 01:50 PM
I'm new in alfresco, but I tried the code above and it works, the only one difference that I realize in the code is a missing include reference in the header:
require_once "Alfresco/Service/Node.php";
After that, all the example worked
I Hope it help you,
Gabriel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2017 03:38 AM
where we have to execute the code the php file
can u please me in detail regarding this or mail me at gaurav.masand09@gmail.com

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2008 07:38 AM
did you find some solutions at this problem? i use the code above but i have the same error!
i also add
require_once ('Alfresco/Service/Node.php');
could you help me please?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2008 03:43 PM
Here's mine.
Maybe will give another clue for the issue.
upload.html
<html> <head></head> <body> <form enctype="multipart/form-data" action="uploadContent.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>
uploadContent.php
<?php require_once 'Alfresco/Service/WebService/WebServiceFactory.php'; require_once 'Alfresco/Service/Repository.php'; require_once 'Alfresco/Service/SpacesStore.php'; $repoURL = "http://localhost:8080/alfresco/api"; $userName = "admin"; $password = "admin"; $repository = new Repository($repoURL); $ticket = $repository->authenticate($userName,$password); $session = $repository->createSession($ticket); $spacesStore = new SpacesStore($session); $companyHome = $spacestore->companyHome; $currentNode = null; $currentNode = $spacesStore->companyHome; $path = 'Company Home'; $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();?>
