Difference between revisions of "PHP Download file"

From OpenKM Documentation
Jump to: navigation, search
(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…')
 
 
Line 31: Line 31:
 
?>
 
?>
 
</source>
 
</source>
 +
 +
More information:
 +
[[http://forum.openkm.com/viewtopic.php?f=5&t=9245&p=21312#p21312 OpenKM forum]]
  
 
[[Category: Utilities]]
 
[[Category: Utilities]]

Latest revision as of 12:41, 10 February 2013

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));
?>

More information: [OpenKM forum]