PHP Download file

From OpenKM Documentation
Revision as of 12:40, 10 February 2013 by Jllort (talk | contribs) (Created page with 'Downloading file using php webservices. Description: * Downloaded file is always pdf header content type is set to '''Content-type: application/pdf''' <source lang="php"> <?php…')

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Downloading file using php webservices.

Description:

  • Downloaded file is always pdf header content type is set to Content-type: application/pdf
<?php
// Register WSDL
$OKMAuth = new SoapClient('http://OpenKM:8080/OpenKM/services/OKMAuth?wsdl');
$OKMDocument = new SoapClient('http://OpenKM:8080/OpenKM/services/OKMDocument?wsdl');
$OKMFolder = new SoapClient('http://OpenKM:8080/OpenKM/services/OKMFolder?wsdl');
// Login
$loginResp = $OKMAuth->login(array('user' => 'okmAdmin', 'password' => 'admin'));
$token = $loginResp->return;

//open document test
$docPath = '/okm:root/Customer Docs/foo/Invoice-0000034.pdf';

//get document content
$getDocumentResp = $OKMDocument->getContent(array('token' => $token, 'docPath' => $docPath, checkout => 0));
$length = strlen($getDocumentResp->return);

//display document response as pdf
header("Content-type: application/pdf");
header("Content-Length: $length");
header("Content-Disposition: inline; filename='test.pdf'");
echo $getDocumentResp->return;

// Logout
$OKMAuth->logout(array('token' => $token));
?>