fmwebschool.com
Top Experts [learn more]Top 4-10
webko

9743 K
bandmandq

2458 K
Genx

1525 K
4. tcmeyers
5. kbata
6. Martie
7. Hammerton
8. rrenfrow
9. bneeman
10. plegler
Welcome, Guest. Please login or register.
May 25, 2013, 11:55:32 AM

Login with username, password and session length
Search:     Advanced search
Welcome to the FileMaker Web Masters Exchange.  If you have any questions about how to use this forum, please watch the getting started movie at:
http://www.fmwebschool.com/movies/forum1/forum1.html
27466 Posts in 6067 Topics by 1523 Members
Latest Member: donok
* Home Help Search Calendar Login Register
+  fmwebschool.com
|-+  PHP Web Publishing Technologies
| |-+  FileMaker's New PHP API
| | |-+  Getting Filename of a user Uploaded File
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: Getting Filename of a user Uploaded File  (Read 742 times)
carmean
Newbie
*
Offline Offline

Posts: 15


« on: June 15, 2012, 03:09:16 PM »

I can't get the name of an uploaded file into the database.  Our form asks a few questions and uploads a user's file to our OS X Snow Leopard (with Filemaker server 10).  I assume this is a common need and would really appreciate an example.

The file is uploaded without any problem and the answers go into a new record (we don't want the file to go into a container, just the file name to go into appropriate field).   

The Input Form has this...
Code:
<!-- Name of input element determines name in $_FILES array -->
   <input name="userfile" type="file" />

as well as the regular entry fields e.g.
Code:
Email: <?php $fieldValue $record->getField('email'0) ; ?><input class="fieldinput" type="text" size="30" maxlength="40" name="<?php echo getFieldFormName('email'0$recordtrue'EDITTEXT''text');?>" value="<?php echo $fieldValue;?>">

and the confirmation form has the regular Filemaker php stuff at the top and I added (in part). 

Code:
// begin Dave B's Q&D file upload security code http://php.net/manual/en/features.file-upload.php
  $allowedExtensions = array("pdf");
 
  foreach ($_FILES as $file) {
    if ($file['tmp_name'] > '') {
      if (!in_array(end(explode(".",
            strtolower($file['name']))),
            $allowedExtensions)) {
       die('<b>' .$file['name'].' is not a PDF file</b>.  ');
      }
    }
  }
  //  end Dave B's Q&D file upload security code
$SafeFile =  $_FILES['userfile']['name']; // was $HTTP_POST_FILES
$SafeFile = str_replace("&", "and", $SafeFile);
$SafeFile = str_replace("*", "1", $SafeFile);

$uploaddir = 'tmp_uploads/';
$uploadfile = $uploaddir  ."New_" . $SafeFile ;

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {

 echo ' <h1>Confirmation of Receipt of Your Application and file ' . $file['name'] . '</h1>
//etc...
                       


Any suggestions for getting $file['name'] into the database?  I would really appreciate some ideas!
Thanks!
Logged
webko
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2051
Kudos: 9743



WWW
Applications:
« Reply #1 on: June 16, 2012, 05:19:20 PM »

Run a FileMaker insert after the upload, with the $file['name'] mapped to the correct field in FileMaker.
Logged

tim.webko_at_gmail.com
carmean
Newbie
*
Offline Offline

Posts: 15


« Reply #2 on: June 19, 2012, 10:29:25 AM »

Run a FileMaker insert after the upload, with the $file['name'] mapped to the correct field in FileMaker.
Thank you for your help!  However, I am not sure you mean by Filemaker insert- do you mean a server script to import  $file['name']  into the submitted record? 

Now I am immediately adding a second record-
Code:
$record = $fm->createRecord('weblayout');
$record->setField('PDFname', $uploadfile);
$record->setField('Last_Name', 'See Above');
$result = $record->commit();

I tried editing the submitted record but was not able to get the recid (and I am not sure I want to open up editing/viewing records to the web user)
Code:
$recid = $result->getRecordID();
$edit = $fm->newEditCommand( 'webentry' , $recid );
$edit->setField('PDFname' , $uploadfile);
$edit->execute();
I also moved the file checking code above the Filemaker api code.
Logged
webko
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2051
Kudos: 9743



WWW
Applications:
« Reply #3 on: June 19, 2012, 06:19:03 PM »

Why not do the insert of the record to FileMaker (aka createRecord) after the upload has been successful? You probably don't want to create a record if the upload fails anyway...
Logged

tim.webko_at_gmail.com
carmean
Newbie
*
Offline Offline

Posts: 15


« Reply #4 on: June 20, 2012, 08:34:20 AM »

You are correct- but my current problem is I am creating two records when I only want one record because I don't know how to extract the filename from the file upload array and get it into the "$recorddata = $cgi->get('recorddata');" of the PHP Site Assistant, even though both are submitted (successfully) in the same form (my 'file upload array' terminology might be wrong).

The process now is
1) Check the upload file to see that it is a PDF (die & warn if not)   
2) Create Safe Filename, Upload File
3) Check to see File is uploaded, if it is,
     3a) Run PHP Site Assistant generated code -- this creates a new record
     3b) Create a second new record with just the filename-
Code:
   $record = $fm->createRecord('web_layout');
   $record->setField('PDFname', $uploadfile);
   $record->setField('email', 'temporary');
   $result = $record->commit();
4) If the File is not uploaded, return a warning to web user.

However, I really want to create just one new record in 3a/b, putting the uploaded filename in that record (preferably at its creation, lacking that, by editing the new record).  If I knew how to get the recid of the new record created I would be able to edit the record.

Thank you again!
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!