Garry Claridge Posted August 21, 2002 Posted August 21, 2002 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
Keith M. Davie Posted August 21, 2002 Posted August 21, 2002 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.
ibiubu Posted August 21, 2002 Posted August 21, 2002 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
Garry Claridge Posted August 21, 2002 Author Posted August 21, 2002 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
Keith M. Davie Posted August 21, 2002 Posted August 21, 2002 Then php does not work on versions of Mac os earlier than X?
Garry Claridge Posted August 21, 2002 Author Posted August 21, 2002 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
spcalia Posted August 21, 2002 Posted August 21, 2002 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'); }
Arin Posted September 11, 2002 Posted September 11, 2002 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
Clinton Posted October 8, 2004 Posted October 8, 2004 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
Garry Claridge Posted October 9, 2004 Author Posted October 9, 2004 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
Recommended Posts
This topic is 7342 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 accountSign in
Already have an account? Sign in here.
Sign In Now