Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

File Upload & PHP

Featured Replies

Here is an example of how to do file uploads and access an FM database with PHP.

First the form:

<body>

<form action="uploadtest.php" method="post" enctype="multipart/form-data">

<input type="file" name="myfile">

<input type="submit" value="Upload">

</form>

</body>

</html>


Second the PHP file:
<body>

<?php

$file_name = $_FILES['myfile']['name'];

move_uploaded_file($_FILES['myfile']['tmp_name'], "/Volumes/Data/" . $_FILES['myfile']['name']);

readfile ("http://10.0.1.2:1154/FMPro?-db=combotest.fp5&-lay=web&-format=hworld.html&name=" . $file_name . "&-new");

?>

File Uploaded

</body>

</html>


The 'hworld.html' format file can contain whatever you like.

Mac OS X comes with Apache and PHP.

Hope this is of interest.

Garry

I'm still struggling with an xml text. (yawn) And i'm not up to php yet. But you da man garry, and I've saved this little nugget in my code db.

Thanks.

OK, this one got my attention. I am running a filemaker database on a iMAX running OSX. I am also serving up the pages to the web. I have been wanting to add the ability to have cliients upload files via a browser interface.

You said OSX comes with apache and php. I was not aware of this. I did some searches and understood that you had to install/activate php on a osx machine and that it was a bit of a sticky process? Same with Apache?

LR

  • Author

The 'Web Sharing' of OS X is Apache. For PHP you have to edit the httpd.conf file to un-comment the lines that refer to PHP.

You place the *.php files in the 'Documents' folder of the 'Web Server' folder. Hey presto that's it.

Notes on how to edit the httpd.conf file, to enable PHP, can be found in the Apple Tech Article ID 106485 Also, I can write some notes on how to edit this file if the need arises.

Hope this helps.

Garry

Then php does not work on versions of Mac os earlier than X?

  • Author

I don't think PHP is available for pre-OS X. However, an old cheap PC with Linux will do the job.

Perhaps Perl and Applescript can be used on pre-X Macs!

Garry

This can also be done eaily in perl. The form gary uses would be the same except that the action would be the perl script instead.

The script uses the perl module CGI.pm. Here is sample code

#! /usr/bin/perl

use CGI qw/:standard/;

####################

#Global Variables

####################

$officeUsername ='test';

$officePassword = 'upload';

####################

print header,

start_html(-title=>'File Upload',

-bgcolor=>'#ffffff'),

h2('File Upload');

print_form() unless param; #print form if not filled out

print_results() if param; #process if form filled in

print end_html;

exit;

sub print_form {

print start_multipart_form,

"

Username:

",

textfield(-name=>'username', -size=>10),br,

"

",

"

Password:",

textfield(-name=>'password', -size=>10),

"

",

"

File to upload:",

filefield(-name=>'upload',-size=>20),

"

",

submit(-label=>'Upload File'),

end_form;

}

sub print_results {

my $length;

my $username = param('username');

my $password = param('password');

my $file = param('upload');

if(!$file && $username != $officeUsername && $password != $officePassword) {

print "No file uploaded. Username/password combination incorrect or no file chosen. Please try again.";

return;

}

#upload and save file

open (SAVE,">./saved_file.txt") || die $!;

while (<$file>) {

print SAVE $_;

}

close SAVE;

print h2('File: ',$file,' --Uploaded Successfully');

}

  • 3 weeks later...

Hi spcalia

I've been trying to use your CGI script, but it doesn't seem to be completing...

Any tips? All I'm getting is a white page that says "File Upload" from the first print statements.

Do you think my CGI handler is having trouble?

My Web Server is a OS X Server v1.2 (the old one) running Tenon's iTools 5

*These are the specifics:

Apache/1.3.19 (iTools/MacOSXS 1.2) mod_ssl/2.7.1 OpenSSL/0.9.5a mod_perl/1.24 mod_fastcgi/2.2.8

-Arin

  • 2 years later...

I was going over your php code for uploading a file into a container field. I was wondering if you could give me some help on your php script...

I was interested mostly in the readfile line... what is each parameter for, exactly? You mention the hworld.html file; what is it for, exactly? I can make sense of most of the rest... first is the location of the database, then the name of the database; the name is gotten from the form... but what about the rest? The lay and format? I'm not familiar with readfile, so i'm not sure how it works exactly, or how to make a format file. I would appreciate any help, thanks.

Also, where do you declare the variable names for the $_FILE array, and the move_uploaded_file function call?

Feel free to e-mail me. Thanks,

-Clinton

  • Author

The parameters of the readfile() are CDML tags (Custom Web Publishing). For example, "-lay" is the FM Layout (not really needed), "-format" is the FM Format file that is returned and would usually contain the CDML replacement tags.

The "$_FILE" is a built-in php array that is returned after the Form is uploaded.

The "move_uploaded_file()" is a built-in php function.

Note that this php script does not insert a file into a Container field. It places the file external to the FM database.

Good Luck.

Garry

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.