예제 #1
0
 function testRead()
 {
     // Set up response for mock client
     $this->response->setBody('Text content');
     $this->response->setInfo(array('content_type' => 'text/text'));
     $this->mockClient->expects($this->any())->method('send')->will($this->returnValue($this->response));
     $doc = new MLPHP\Document($this->mockClient);
     $result = $doc->read($doc->getURI());
     $this->assertEquals($result, $doc->getContent());
     $this->assertEquals('text/text', $doc->getContentType());
 }
예제 #2
0
파일: binary.php 프로젝트: marklogic/mlphp
<?php

/*
Copyright 2002-2012 MarkLogic Corporation.  All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
use MarkLogic\MLPHP;
// Set up global vars and class autoloading
require_once 'setup.php';
// Create a REST client object for the MarkLogic database
$client = $mlphp->newClient();
$doc = new MLPHP\Document($client);
$uri = $_REQUEST['uri'];
$parts = explode('/', $uri);
$filename = end($parts);
$content = $doc->read($uri);
header('Content-Type: ' . $doc->getContentType());
header('Content-Disposition: attachment; filename=' . $filename);
echo $content;
예제 #3
0
// Binary image file
$doc4 = new MLPHP\Document($client);
// Create a Document object (passing the REST client)
$file4 = 'example.jpg';
// Define the path to the file to write
$doc4->setContentType('image/jpeg');
// Set the content type for the document
$doc4->setContentFile($file4);
// Set the file as the document content
$uri4 = '/' . $file4;
// Define the URI for the document
$doc4->write($uri4);
// Write the document to the database
// Embed the binary image file in a page with HTML
echo "Display the image document:\n";
displayImage($uri4, $doc4->getContentType());
// Helper function
echo "\n\n";
// Binary PDF file
$doc5 = new MLPHP\Document($client);
// Create a Document object (passing the REST client)
$file5 = 'example.pdf';
// Define the path to the file to write
$doc5->setContentType('application/pdf');
// Set the content type for the document
$doc5->setContentFile($file5);
// Set the file as the document content
$uri5 = '/' . $file5;
// Define the URI for the document
$doc5->write($uri5);
// Write the document to the database