示例#1
2
function fmGetContainer($fm_databases)
{
    // Determine the resource that is being requested via the _SERVER scope.
    // ex: http://localhost/dynamic-containers/530f982c01733/1393530924/Sample.pdf
    if (isset($_SERVER['SCRIPT_URI'])) {
        $resource_requested = $_SERVER['SCRIPT_URI'];
    } elseif (isset($_SERVER['REDIRECT_URL'])) {
        $resource_requested = $_SERVER['REDIRECT_URL'];
    } else {
        die('fmGetContainer: Unable to determine the resource that was requested.');
    }
    // Remove the Root URL from the resource requested.
    // This resolves issues encountered when the Web app is in a sub-folder.
    // Example: /containers/macmini.png
    $resource_requested = fmSubstitute($resource_requested, HTTP_ROOT_URL, '');
    // Remove the virtual container folder from the resource requested.
    // This resolves issues encountered when the Web app is in a sub-folder.
    // Example: /macmini.png
    $resource_requested = fmSubstitute($resource_requested, CONTAINER_FOLDER, '');
    // fmDump ( $resource_requested, TRUE, 'resource_requested' );
    // Get the resource's info file name.
    // Example: macmini.png.info
    $info_file_name = fmSubstitute($resource_requested, '/', '-');
    $info_file_name = fmRight($info_file_name, fmLength($info_file_name) - 1);
    $info_file_name .= '.info';
    // fmDump ( $info_file_name, TRUE, 'info_file_name' );
    // Get the OS path that was used to store the container's info file.
    // Example: /domains/demo.fmwebframe.com/html/FMWebFrame/../temp/macmini.png.info
    $physical_path_container_info_file = CONTAINER_PATH . '/' . $info_file_name;
    // fmDump ( $physical_path_container_info_file, TRUE, 'physical_path_container_info_file' );
    // If the info file wasn't found...
    if (!file_exists($physical_path_container_info_file)) {
        // Return control to the 404 error handler.
        return;
    }
    // Read the info file.
    $info_file_contents = @file_get_contents($physical_path_container_info_file);
    // fmDump ( $info_file_contents, TRUE, 'info_file_contents' );
    // Convert the contents of the info file into an array.
    $container_info_array = preg_split("/\n/", $info_file_contents);
    // fmDump ( $container_info_array, TRUE, 'container_info_array' );
    // Break the array up into variables for easier reference.
    $container_field_as_text = $container_info_array[0];
    $maximum_age = $container_info_array[1];
    $access_rule = $container_info_array[2];
    // Get the OS path that will be used to get/save the container's binary contents.
    // Example: /domains/demo.fmwebframe.com/html/FMWebFrame/../temp/macmini.png
    $physical_path_container_contents_file = fmLeft($physical_path_container_info_file, fmLength($physical_path_container_info_file) - 5);
    // fmDump ( $physical_path_container_contents_file, TRUE, 'physical_path_container_contents_file' );
    // If the URL is only valid for a certain amount of time...
    if ($maximum_age > 0) {
        // Get the age of the info file.
        $file_age = time() - filemtime($physical_path_container_info_file);
        // fmDump ( $file_age, TRUE, 'file_age' );
        // If the URL has expired...
        if ($file_age >= $maximum_age) {
            // Delete the "stale" files.
            @unlink($physical_path_container_contents_file);
            @unlink($physical_path_container_info_file);
            // Return control to the 404 error handler.
            return;
        }
    }
    // If an access rule was specified...
    if ($access_rule !== '') {
        // Evaluate the rule.
        $allow_access = eval('return (' . $access_rule . ');');
        //fmDump ( $access_rule, FALSE, 'access_rule' );
        //fmDump ( $allow_access, TRUE, 'allow_access' );
        // If the rule failed...
        if (!$allow_access) {
            // Replace the 404 response with a "403 Forbidden" and die.
            header('Status: 403', TRUE, 403);
            die;
        }
    }
    // Split the container's text value into an array so that we can isolate the file name & container info.
    $container_field_array = explode('?', $container_field_as_text);
    // fmDump ( $container_field_array, TRUE, 'container_field_array' );
    // Get the file name (the first element of the "container_field_array" array).
    $filename = $container_field_array[0];
    $filename = fmsubstitute($filename, '/fmi/xml/cnt/', '');
    $filename = urldecode($filename);
    $filename = fmsubstitute($filename, ' ', '-');
    // fmDump ( $filename, TRUE, 'filename' );
    // Parse the second element of the "container_field_array" array into individual variables.
    // Note: parse_str parses a query string into variables.
    // ex: -db=FMWebFrame_Demo&-lay=Resource%20-%20Form&-recid=2&-field=Resource(1)
    // ---> db = FMWebFrame_Demo
    // ---> lay = Resource - Form
    // ---> recid = 2
    // ---> field = Resource(1)
    // Note that we're most interested in the database name, which we need in order to
    // determine the database connection info to use should we need to refer back to
    // the record that the container was pulled from.
    $container_info = html_entity_decode($container_field_array[1]);
    $container_info = fmsubstitute($container_info, '-db', 'db');
    $container_info = fmsubstitute($container_info, '&-', '&');
    parse_str($container_info);
    // fmDump ( $db, TRUE, 'db' );
    // If the container contents file is available...
    if (file_exists($physical_path_container_contents_file)) {
        // Read the file.
        $container_data = @file_get_contents($physical_path_container_contents_file);
    } else {
        // Using the database name, find the database connection to use...
        foreach ($fm_databases as $fm_database) {
            // If the connection was found...
            if ($fm_database['database'] == $db) {
                // Create a connection to the database.
                $fm = new FileMaker();
                $fm->setProperty('hostspec', $fm_database['hostspec']);
                $fm->setProperty('database', $fm_database['database']);
                $fm->setProperty('username', $fm_database['username']);
                $fm->setProperty('password', $fm_database['password']);
                break;
            }
        }
        if (!isset($fm)) {
            // Return control to the 404 error handler.
            return;
        }
        // fmDump ( $fm, TRUE, 'fm' );
        // Get the record that the container was pulled from.
        $container_record = $fm->getRecordById($lay, $recid);
        // fmDump ( $container_record, TRUE, 'container_record' );
        // Get the container data.
        $container_data = $fm->getContainerData($container_field_as_text);
        if (FileMaker::isError($container_data)) {
            die;
        }
        // fmDump ( $container_data, FALSE, 'container_data' );
        // Save the container's contents on the server.
        @file_put_contents($physical_path_container_contents_file, $container_data);
    }
    // If we have the container's content...
    if (isset($container_data)) {
        // Update the http response header, so that this does not appear to be a "404."
        header('Status: 200', TRUE, 200);
        // Explode the filename to get the extension.
        $filename_parts = explode('.', $filename);
        $extension = $filename_parts[1];
        // If the extension includes a URL request...
        if (fmPatternCount($extension, '?')) {
            $extension_parts = explode('?', $extension);
            $extension = $extension_parts[0];
        }
        // Setup the headers to use, based on the file type (extension).
        switch ($extension) {
            case 'gif':
                header('Content-type: image/gif');
                header('Content-Disposition: filename="' . $filename . '"');
                break;
            case 'jpeg':
                header('Content-type: image/jpeg');
                header('Content-Disposition: filename="' . $filename . '"');
                break;
            case 'jpg':
                header('Content-type: image/jpeg');
                header('Content-Disposition: filename="' . $filename . '"');
                break;
            case 'mov':
                header('Content-type: video/quicktime');
                header('Content-Disposition: filename="' . $filename . '"');
                break;
            case 'mp3':
                header('Content-type: audio/mpeg');
                header('Content-Disposition: filename="' . $filename . '"');
                break;
            case 'mp4':
                header('Content-type: video/mp4');
                header('Content-Disposition: filename="' . $filename . '"');
                break;
            case 'ogg':
                header('Content-type: application/ogg');
                header('Content-Disposition: filename="' . $filename . '"');
                break;
            case 'pdf':
                header('Content-type: application/pdf');
                header('Content-Disposition: filename="' . $filename . '"');
                break;
            case 'png':
                header('Content-type: image/png');
                header('Content-Disposition: filename="' . $filename . '"');
                break;
            default:
                header('Content-type: application/force-download');
                header('Content-Transfer-Encoding: Binary');
                header('Content-Disposition: attachment; filename="' . $filename . '"');
        }
        // Send additional headers.
        header('Content-Length: ' . strlen($container_data));
        header('Cache-Control: private');
        // Send the container's binary data.
        echo $container_data;
        die;
    }
}
示例#2
0
 /**
  * @covers \airmoi\FileMaker\FileMaker::setProperty
  */
 public function testSetProperty()
 {
     $this->fm->setProperty('logLevel', FileMaker::LOG_INFO);
     //Test valid property
     $this->assertEquals(FileMaker::LOG_INFO, $this->fm->getProperty('logLevel'));
     //Test invalid property (should return an error)
     if (!$GLOBALS['OFFICIAL_API']) {
         $this->setExpectedException(FileMakerException::class);
         $this->fm->setProperty('fakeProperty', FileMaker::LOG_INFO);
     }
 }
示例#3
0
 * other intellectual property license or right is granted, either expressly or
 * by implication, by FileMaker.
 * 
 * Example PHP script to illustrate how to list databases on the server.
 * 
 * Requirements:
 *   1. Working FileMaker Server installation
 *   2. 'FMPHP_Sample' database hosted in FileMaker Server
 *
 */
// Include FileMaker API
require_once 'FileMaker.php';
// Create a new connection to server without specifying database or hostspec.
$fm = new FileMaker();
// Set 'hostspec' property using setProperty()
$fm->setProperty('hostspec', 'http://localhost');
$databases = $fm->listDatabases();
// If an error is found, return a message and exit.
if (FileMaker::isError($databases)) {
    printf("Error %s: %s\n", $databases->getCode());
    "<br>";
    printf($databases->getMessage());
    exit;
}
// Print out layout names
foreach ($databases as $db) {
    echo "{$db}<br>";
}
?>
</body>
</html>
示例#4
0
 *
 * Copyright 2006 FileMaker, Inc. Alle Rechte vorbehalten.
 * HINWEIS: Die Verwendung des Quellcodes unterliegt den Bestimmungen der
 * FileMaker-Softwarelizenz, die dem Quellcode beliegt. Durch Ihre Verwendung
 * des Quellcodes erklären Sie sich mit diesen Lizenzbestimmungen einverstanden.
 * Mit Ausnahme der ausdrücklich in der Softwarelizenz gewährten Rechte werden
 * keine anderen Urheberrechts-, Patent- oder anderen Lizenzen/Rechte an geistigem
 * Eigentum von FileMaker, Inc. gewährt, weder ausdrücklich noch stillschweigend.
 *
 */
/**
 * Die Datei ist für Erstellung/Initialis. des FileMaker-Objekts verantwortlich.
 * Mit dem Objekt können Sie Daten in der Datenbank ändern. Schließen Sie hierzu 
 * die Datei in die PHP-Datei ein, die auf die FileMaker-Datenbank zugreifen muss.
 */
//FileMaker PHP API einschließen
require_once 'FileMaker.php';
//FileMaker-Objekt erstellen
$fm = new FileMaker();
//FileMaker-Datenbank angeben
$fm->setProperty('database', 'questionnaire');
//Host angeben
$fm->setProperty('hostspec', 'http://localhost');
//temporär auf einem lokalen Server bereitgestellt
/**
 * Verwenden Sie für den Zugriff auf die Datenbank das Standard-Administratorkonto,
 * das kein Passwort besitzt. Authentifizierung ändern: Öffnen Sie die Datenbank in
 * FileMaker Pro und wählen Verwalten > Konten und Zugriffsrechte (Menü "Datei").
 */
$fm->setProperty('username', 'web');
$fm->setProperty('password', 'web');
示例#5
0
<?php

// If we're using FileMaker on the backend...
if (FM_HOSTSPEC != '') {
    // Load the FileMaker API for PHP.
    require_once FM_API_PATH . 'FileMaker.php';
    // Create a FileMaker connection object.
    $fmSwipe = new FileMaker();
    $fmSwipe->setProperty('hostspec', FM_HOSTSPEC);
    $fmSwipe->setProperty('database', FM_DATABASE);
    $fmSwipe->setProperty('username', FM_USERNAME);
    $fmSwipe->setProperty('password', FM_PASSWORD);
}
// If we're using MySQL on the backend...
if (MYSQL_HOSTSPEC != '') {
    // Create a MySQL connection object.
    $fmMySQL = new mysqli(MYSQL_HOSTSPEC, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_DATABASE);
    // If the connection has failed...
    if ($fmMySQL->connect_error) {
        // Start output buffering.
        ob_start();
        echo '<h1 id="https-enforcer-header"><span>Database Connection Error</span></h1>';
        echo '<div id="https-enforcer-message-1"><span>The attempt to connect resulted in error ' . $fmMySQL->connect_error . '.</span></div>';
        // Grab the contents of the output buffer.
        $ui_body_content = ob_get_contents();
        // End output buffering, and erase the contents.
        ob_end_clean();
        // Set page title.
        $ui_title = 'Database Connection Error';
        // Display the page, using the template.
        require_once dirname(__FILE__) . '/page-template.php';
<?php

require_once 'config_inclusion_first.php';
require_once 'FileMaker.php';
$inclusionFirst = new FileMaker();
$inclusionFirst->setProperty('database', DATABASE);
$inclusionFirst->setProperty('hostspec', HOSTSPEC);
$inclusionFirst->setProperty('username', USERNAME);
$inclusionFirst->setProperty('password', PASSWORD);
		History:
				
			2015-04-01
				Tim Dietrich (timdietrich@me.com)
				Initial version.
				
			2015-05-31
				Tim Dietrich (timdietrich@me.com)
				Beta 2.1 code review.					
*/
// Load the FileMaker API for PHP.
require_once dirname(__FILE__) . '/../libraries/FileMaker/FileMaker.php';
// Create a FileMaker connection object.
$fm = new FileMaker();
$fm->setProperty('hostspec', FM_HOSTSPEC);
$fm->setProperty('database', FM_DATABASE);
// If the user is logging in...
if ($_POST['fm_account_name'] != '' and $_POST['fm_password'] != '') {
    // Use the account name and password that they provided.
    $fm->setProperty('username', $_POST['fm_account_name']);
    $fm->setProperty('password', $_POST['fm_password']);
} elseif ($_SESSION['fm_account_name'] != '' and $_SESSION['fm_password'] != '') {
    // The user has previously authenticated, and we'll use their credentials...
    // First, get the initialization vector that was used to encrypt the credentials.
    $iv = base64_decode($_COOKIE[EW_IV_COOKIE_NAME]);
    // Decrypt credentials and assign them to the connection object.
    $fm->setProperty('username', decrypt($_SESSION['fm_account_name'], $encryption_key, $iv));
    $fm->setProperty('password', decrypt($_SESSION['fm_password'], $encryption_key, $iv));
} else {
    // Use the default credentials.
示例#8
0
<?php

require_once 'config_kosmas.php';
require_once 'FileMaker.php';
$kosmas = new FileMaker();
$kosmas->setProperty('database', DATABASE);
$kosmas->setProperty('hostspec', HOSTSPEC);
$kosmas->setProperty('username', USERNAME);
$kosmas->setProperty('password', PASSWORD);
	
		Dependents:
			/FMWebFrame/FMWebFrame.php
	
		Version:
			1
	
		History:
		
			2013-12-18	Tim Dietrich
				Initial version.
*/
// Loop over elements in the $fm_databases array...
foreach ($fm_databases as $fm_database) {
    // Create a connection object.
    $fm = new FileMaker();
    $fm->setProperty('hostspec', $fm_database['hostspec']);
    $fm->setProperty('database', $fm_database['database']);
    $fm->setProperty('username', $fm_database['username']);
    $fm->setProperty('password', $fm_database['password']);
    // Create the name for the connection object.
    $nickname = $fm_database['nickname'];
    // Assign the name to the connection object.
    // Note the "$$" prefix.
    // See "Variable variables" discussed here: http://php.net/manual/en/language.variables.variable.php
    ${$nickname} = $fm;
    // Test the database.
    if (TEST_DB_CONNECTIONS) {
        fmDatabaseTest($fm_database['nickname'], ${$nickname});
    }
}