使用 FileMaker Pro & PHP 从容器字段回显编码图像
Echo Encoded Image from Container Field using FileMaker Pro & PHP
如何通过 PHP 访问存储在 FileMaker Pro 数据库的嵌入式容器字段中的图像并回显到本机 iOS 应用程序?有几个关于获得 url 的参考资料,但没有关于将图像回显为编码字符串的具体内容。
以下是更详细的步骤:
- iOS 应用程序通过 POST 将 recordId 传递到 PHP 文件。
- PHP 文件获取匹配记录
- PHP 文件获取包含图像的容器字段(这是怎么做到的?)
- PHP 文件将图像编码为文本(这是怎么做到的?)
- PHP 文件回显编码图像
- Swift 项目在 UIImageView 中显示图像
由于我只使用类似的方法在 FileMaker Server 和本机 iOS 应用程序之间来回移动文本,因此我正在寻求对图像执行相同操作的指导,特别是第 4 步。
虽然评论中提到的 article 是一个好的开始,但一般的解决方案是使用 FileMaker PHP API 教程中的容器桥接文件。我相信教程文件(一个 HTML 文件,每节课都有文件夹)是随 FileMaker Server 安装的。
无论如何,本教程的第 2 课介绍了 ContainerBridge.php 文件,其中包含以下内容(在某个地方显然必须有更新的版本中):
<?php
/**
* FileMaker PHP Example
*
*
* Copyright 2006, FileMaker, Inc. All rights reserved.
* NOTE: Use of this source code is subject to the terms of the FileMaker
* Software License which accompanies the code. Your use of this source code
* signifies your agreement to such license terms and conditions. Except as
* expressly granted in the Software License, no other copyright, patent, or
* other intellectual property license or right is granted, either expressly or
* by implication, by FileMaker.
*
*/
//This is a bridge script that calls FileMaker::getContainerData with the provided url.
require_once("dbaccess.php");
if (isset($_GET['path'])){
$url = $_GET['path'];
$url = substr($url, 0, strpos($url, "?"));
$url = substr($url, strrpos($url, ".") + 1);
if($url == "jpg"){
header('Content-type: image/jpeg');
}
else if($url == "gif"){
header('Content-type: image/gif');
}
else{
header('Content-type: application/octet-stream');
}
echo $fm->getContainerData($_GET['path']);
}
?>
想法是 dbaccess.php
文件创建 FileMaker 对象并设置 URL、用户名和密码,以便正确启动 $fm
对象。当您需要访问容器数据时,您可以包含此 ContainerBridge.php 文件并将其用作 URL.
echo '<img src="ContainerBridge.php?path=' . urlencode($record->getField('Image')) . '">';
我不确定您使用的是哪个版本的 FileMaker,或者您是否有权访问 table 结构,但如果您有权访问并且使用的是最新版本(截至在撰写本文时),您可以创建一个计算字段,该字段对容器字段进行 base64 编码(Base64Encode 函数)。我相信您可以在 Swift.
中解码 base64
因此,不要将容器字段放在 PHP 正在访问的布局上,而是将此计算字段放在布局上。然后,您在 PHP 中需要做的就是回显 base64 字符串,这样就可以同时处理第 3、4 和 5 步。
希望对您有所帮助!
如何通过 PHP 访问存储在 FileMaker Pro 数据库的嵌入式容器字段中的图像并回显到本机 iOS 应用程序?有几个关于获得 url 的参考资料,但没有关于将图像回显为编码字符串的具体内容。
以下是更详细的步骤:
- iOS 应用程序通过 POST 将 recordId 传递到 PHP 文件。
- PHP 文件获取匹配记录
- PHP 文件获取包含图像的容器字段(这是怎么做到的?)
- PHP 文件将图像编码为文本(这是怎么做到的?)
- PHP 文件回显编码图像
- Swift 项目在 UIImageView 中显示图像
由于我只使用类似的方法在 FileMaker Server 和本机 iOS 应用程序之间来回移动文本,因此我正在寻求对图像执行相同操作的指导,特别是第 4 步。
虽然评论中提到的 article 是一个好的开始,但一般的解决方案是使用 FileMaker PHP API 教程中的容器桥接文件。我相信教程文件(一个 HTML 文件,每节课都有文件夹)是随 FileMaker Server 安装的。
无论如何,本教程的第 2 课介绍了 ContainerBridge.php 文件,其中包含以下内容(在某个地方显然必须有更新的版本中):
<?php
/**
* FileMaker PHP Example
*
*
* Copyright 2006, FileMaker, Inc. All rights reserved.
* NOTE: Use of this source code is subject to the terms of the FileMaker
* Software License which accompanies the code. Your use of this source code
* signifies your agreement to such license terms and conditions. Except as
* expressly granted in the Software License, no other copyright, patent, or
* other intellectual property license or right is granted, either expressly or
* by implication, by FileMaker.
*
*/
//This is a bridge script that calls FileMaker::getContainerData with the provided url.
require_once("dbaccess.php");
if (isset($_GET['path'])){
$url = $_GET['path'];
$url = substr($url, 0, strpos($url, "?"));
$url = substr($url, strrpos($url, ".") + 1);
if($url == "jpg"){
header('Content-type: image/jpeg');
}
else if($url == "gif"){
header('Content-type: image/gif');
}
else{
header('Content-type: application/octet-stream');
}
echo $fm->getContainerData($_GET['path']);
}
?>
想法是 dbaccess.php
文件创建 FileMaker 对象并设置 URL、用户名和密码,以便正确启动 $fm
对象。当您需要访问容器数据时,您可以包含此 ContainerBridge.php 文件并将其用作 URL.
echo '<img src="ContainerBridge.php?path=' . urlencode($record->getField('Image')) . '">';
我不确定您使用的是哪个版本的 FileMaker,或者您是否有权访问 table 结构,但如果您有权访问并且使用的是最新版本(截至在撰写本文时),您可以创建一个计算字段,该字段对容器字段进行 base64 编码(Base64Encode 函数)。我相信您可以在 Swift.
中解码 base64因此,不要将容器字段放在 PHP 正在访问的布局上,而是将此计算字段放在布局上。然后,您在 PHP 中需要做的就是回显 base64 字符串,这样就可以同时处理第 3、4 和 5 步。
希望对您有所帮助!