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...
<!-- Name of input element determines name in $_FILES array -->
<input name="userfile" type="file" />
as well as the regular entry fields e.g.
Email: <?php $fieldValue = $record->getField('email', 0) ; ?><input class="fieldinput" type="text" size="30" maxlength="40" name="<?php echo getFieldFormName('email', 0, $record, true, 'EDITTEXT', 'text');?>" value="<?php echo $fieldValue;?>">
and the confirmation form has the regular Filemaker php stuff at the top and I added (in part).
// 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!