Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 6022 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I've just spent the last day and a half figuring out how to use the container bridge to grab any kind of content out of a container field. (users who were only going to drop in images started dropping in pdfs, then someone added a ppt file for good measure). At any rate the container data gets added by one set of users via the FMP client and viewed by another set via the PHP API. Simply adding header('Content-type: application/octet-stream') to all .cnt url references caused Firefox to download the php file and was just ignored by IE.

I used PEAR's HTTP_Request Package http://pear.php.net/package/HTTP_Request to come up with the following solution.

<?php



require_once("FileMaker.php");

require_once('HTTP/Request.php');

$FMServer = "http://myFMserver.myHost.com";

$database = 'myDB';

$user = "username";

$password = "password";



$fm = new FileMaker($database, $FMServer ,$user, $password);



$record = $fm->getRecordById("myLayout", $_GET['RecID']);



if (FileMaker::isError($record)) {

	    echo "Error: {$record->getMessage()}n";

	    exit;

}



$url = $FMServer. $record->getField("myContainer") ; 

$r = new HTTP_Request($url); 

$r->setBasicAuth($user, $password);



			

$r->sendRequest();

$httpResponseCode = $r->getResponseCode();



if ( $httpResponseCode == 401 ) {  

	// Handle Unauthorized

	header("HTTP/1.0 401 Unauthorized");

	exit;

} elseif ( $httpResponseCode == 404  ) {  

	// Handle File not found	

	header("HTTP/1.0 404 Not Found");

	exit;

}else { 

	$headers = $r->getResponseHeader();

	if (substr($headers['content-disposition'], -3) == "pdf") { //if you want pdfs to show in the browser rather than force download

		header('Content-Type: application/pdf');

		$headers['content-disposition'] = str_replace("attachment", "inline",  $headers['content-disposition'] );

	}else{

	 	header("Content-type: " . $headers['content-type']);

	}

        header("Content-disposition: " . $headers['content-disposition']);

	header("Content-length: " . $headers['content-length']);

	print $r->getResponseBody();

}

?>

Posted

Thanks.

I got it working using cURL as well, but it's part of a lager object I'm writing to handle containers. I'm happy to post the obj when I'm done with it. What's the preference for posting code (between code tags of course) vs. attaching a file?

  • 2 weeks later...

This topic is 6022 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.