.com Solutions Inc. - logo  
Products - Header Buttons
.
Repgen bullet item 7b Installgen bullet item 7b FmPro Migratorbullet item 7b CGIScripter
.
.
.

.
.

FmPro Migrator - MySQL Files - Title Graphic

FmPro Migrator Features and Benefits

FmPro Migrator Demo Available for download...

Bookmark This Page

email a friend

.

#!/usr/bin/perl
# Script: contact_management_fmpro_image_export1.pl
# Features: This Perl program exports the JPEG
# image data from the specified FileMaker
# container field to the specified output
# directory.
#
# Requirements:
# Perl DBI module
# Perl DBD::ODBC module reads data from FileMaker
# FileMaker ODBC driver.
# FileMaker must be running in Multi-User mode
# with the Local and Remote Data Access Companions
# enabled. The ODBC Max Text Length parameter
# needs to be increased from 255 to 65000.
# The name of the FileMaker database must not
# contain spaces or special characters.
#
# Database Connection:
# FileMaker ODBC DSN Name: contact_management_fmp_dsn
#
# Usage: perl contact_management_fmpro_image_export1.pl
#
# Used By: run manually by the FileMaker developer
# Copyright 2003 by .com Solutions Inc.
#
# ---------------------- Revision History ---------------
# Date By Changes
# 6-11-2003 dsimpson Initial Release
#
# This output file was created by FmPro Migrator version 1.46 on Sat Jul 12 10:14:45 2003. By .com Solutions Inc. www.dotcomsolutionsinc.net
#

use strict;
use DBI qw(:sql_types);

# FileMaker field names must not contain spaces or special characters
my $fmpro_image_data_field = 'image_field';
my $fmpro_image_filename_field = 'filename_field';
# Windows pathnames require \ instead of just as directory separators
my $image_output_directory_path = 'c:\\my_images\\'; # directory path needs to include trailing directory separator
my $db_connect_string_fmpro = 'contact_management_fmp_dsn';
my $filemaker_database_name = 'contact_management';
my $debug=0; # DBI tracing enable/disable
my $long_readlength = 100000; # maximum number of bytes for each image read from FileMaker - increase this value as needed
my $record_count=0;
my @rowdata = ();

# ---------- fixup_container_data -----------
# This sub removes the HTTP 1.0 data which usually
# prefixes FileMaker Pro container field data.

sub fixup_container_data
{
my $rowdata_count = $_[0]; # get rowdata array element number passed into this sub
my $prefix_position=0;

my $temp_string=substr($rowdata[$rowdata_count],0,200);
if (substr($rowdata[$rowdata_count],0,4) eq "HTTP" )
{
# if 1st 4 characters of container field data contains the text "HTTP" then
# this prefix data needs to be removed before insertion into the DB2 table

$temp_string =~ /Content-length: /g;
# find the position within the data which contains the "Content-length: " text
$prefix_position = pos($temp_string);

# loop until end of numeric value defining content-length is reached
while (substr($temp_string,$prefix_position,1) =~ /\d/)
{
$prefix_position++;
}
$prefix_position += 4;

if ($prefix_position < 200)
{
# truncate the container field prefix info - only if within the 1st 200 bytes
substr($rowdata[$rowdata_count],0,$prefix_position)="";
}

}
}
# ---------- fixup_container_data -----------

my $fmpro_dbh = DBI->connect ("dbi:ODBC:$db_connect_string_fmpro", "", "", {RaiseError => 1, PrintError => 1, AutoCommit => 0})
or die "Can't connect to the FileMaker $db_connect_string_fmpro database: $DBI::errstr\n";
$fmpro_dbh->{LongReadLen} = $long_readlength;
$fmpro_dbh->{LongTruncOk} = 0;

if ($debug == 1)
{
# turn on DBI tracing
unlink 'dbitrace.log' if -e 'dbitrace.log';
DBI->trace(2, 'dbitrace.log');
}

# ----------- retrieve records from FileMaker
my $fmpro_sth = $fmpro_dbh->prepare("select $fmpro_image_data_field,$fmpro_image_filename_field from $filemaker_database_name");

$fmpro_sth->execute();

while ( @rowdata = $fmpro_sth->fetchrow_array())
{
# $rowdata[0] - image data
# $rowdata[1] - image filename
# Both image data and filename need to be > 0 in order to export the data
if ((length($rowdata[0]) > 0) and (length($rowdata[1]) > 0 ))
{
# strip uneeded info from container field data
&fixup_container_data(0);
open (OUTPUTFILE1, ">$image_output_directory_path$rowdata[1]") || warn ("Could not open input file $image_output_directory_path$rowdata[1], does the directory exist?");
binmode(OUTPUTFILE1);
print OUTPUTFILE1 $rowdata[0];
close (OUTPUTFILE1);
my $image_size = length($rowdata[0]);
print "$rowdata[1] image size $image_size\n"; # print the image size
}

$record_count++;
print "Processed record# $record_count\n";
}

$fmpro_sth->finish();

# disconnect from FileMaker database
$fmpro_dbh->disconnect or warn "Can't disconnect from the FileMaker $db_connect_string_fmpro database: $DBI::errstr\n";

print "***********************************************\n";
print "Completed exporting FileMaker image data.\n";
print "***********************************************\n";
print "$record_count Records processed.\n";
print "***********************************************\n";

exit;


.

hline

. .

.

. .
 

Home | Products | Services | Downloads | Order | Support | Contact

Legal Notices

.
.   .
.
Home Products Services Downloads Order Support Contact