Jump to content
Server Maintenance This Week. ×

Getting the Filename of an Uploaded file into Filemaker


This topic is 4351 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have a single form that asks a person to answer questions (name etc) and upload a file to the server using

<input name="PDFname" type="file" />

Works Beautifully- when the information and file are uploaded successfully the user gets the message

echo ($file['name']. ' was successfully uploaded to the server'

I don't know how to get the name of the uploaded file into Filemaker.

Any suggestions are welcome! I think it should be simple.

From my reading I think I have to join the information $_FILES['file']['name'] from the $_FILES array with this

// get the submitted record data

$recorddata = $cgi->get('recorddata');

if (isset ($recorddata)) {

// submit the data to the db

$result = submitRecordData($recorddata, $newrecordrequest, $cgi, $layout->listFields());

I looked at using @session_start(); hoping I could forward all the information, but I hope there is a more direct way (andI don't know if that will work).

For security I only allow the web account to add new records, not view or edit. We are using Filemaker 10 server on Snow Leopard client (we have Filemaker 11 but not installed yet), and have using files heavily modified from the site assistant.

This is the confirmation php file:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<?php

/**

* FileMaker PHP Site Assistant Generated File

*/

require_once 'fmview.php';

require_once 'FileMaker.php';

require_once 'error.php';

$cgi = new CGI();

$cgi->storeFile();

... Database & password etc...

$fm = & new FileMaker();

$fm->setProperty('database', $databaseName);

$fm->setProperty('username', $userName);

$fm->setProperty('password', $passWord);



ExitOnError($fm);

$layout = $fm->getLayout($layoutName);

ExitOnError($layout);

// formats for dates and times

$displayDateFormat = '%m/%d/%Y';

$displayTimeFormat = '%I:%M:%S %P';

$displayDateTimeFormat = '%m/%d/%Y %I:%M:%S %P';

$submitDateOrder = 'mdy';

// create the new add command

$newrecordrequest = $fm->newAddCommand($layoutName);

ExitOnError($newrecordrequest);

// get the submitted record data

$recorddata = $cgi->get('recorddata');

if (isset ($recorddata)) {

	 // submit the data to the db

	 $result = submitRecordData($recorddata, $newrecordrequest, $cgi, $layout->listFields());

	 // clear the stored record data

	 $cgi->clear('recorddata');

	 ExitOnError($result);

	 if ($result->getFetchCount() > 0) {

		 $records = $result->getRecords();

		 $record = $records[0];

	 }

}

ExitOnError($record);

?>

<html xmlns="http://www.w3.org/1999/xhtml"><head>

<meta http-equiv="content-type" content="text/html; charset=utf-8">

<title>Biological Sciences</title></head>

<body>	

<?php

$timestamp = time();

// 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>. <h2> <a href="index.php">Go back to the form</a> <h2> ');

	 }

}

}

// end Dave B's Q&D file upload security code

$SafeFile = $_FILES['PDFname']['name']; // was $HTTP_POST_FILES

$SafeFile = str_replace("#", "No", $SafeFile);

$SafeFile = str_replace("$", "Dollar", $SafeFile);

$SafeFile = str_replace("%", "Percent", $SafeFile);

$SafeFile = str_replace("^", "-", $SafeFile);

$SafeFile = str_replace("&", "and", $SafeFile);

$SafeFile = str_replace("*", "1", $SafeFile);

$SafeFile = str_replace("?", "2", $SafeFile);

$SafeFile = str_replace(":", "3", $SafeFile);

$uploaddir = 'tmp_applicant_uploads/';

$uploadfile = $uploaddir . $timestamp ."_" . $SafeFile ;

echo '<div>';

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

echo '	 <table cellpadding="0" cellspacing="0" class="contentbg">



<tr><td class="contentbgleft"> </td><td >



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



<table cellpadding="1" cellspacing="0" class="recwidth"><tr><td valign="top"> ';

echo ($file['name'].' was successfully uploaded <br/>');

	

// Read and write for owner, read for everybody else (not used here)

// chmod($uploadfile, 0644);	

	

} else {

echo "The file was not uploaded (but your information was processed!).\n";

	 }

// echo '<br/><br/>Here is some more debugging info:';

// print_r($_FILES);

print "</div>";

?>





and the form:



<form enctype="multipart/form-data" action="confirmation_short.php" method="Post">								

<input type="hidden" name="-db" value="<?php echo $databaseName ?>"> <input type="hidden" name="-lay" value="<?php echo $layoutName ?>"> <input type="hidden" name="-action" value="new">

		

<table cellpadding="1" cellspacing="6" class="record">

<tr><td align="right" valign="top">

Position: </td><td>

<?php $fieldValue = $record->getField('position', 0) ; ?><?php getInputChoices("radio", $layout->getValueListTwoFields('position', (isset($master_record)) ? $master_record->getRecordId() : $record->getRecordId()), $fieldValue, getFieldFormName('position', 0, $record, true, 'RADIOBUTTONS', 'text'), 'text', $submitDateOrder);?></td> </tr>

		

<tr onkeypress="return event.keyCode != 13;">

<td align="right">First Name:</td> <td><?php $fieldValue = $record->getField('First_Name', 0) ; ?><input type="text" size="30" maxlength="40" name= "<?php echo getFieldFormName('First_Name', 0, $record, true, 'EDITTEXT', 'text');?>" value="<?php echo $fieldValue;?>"> Last Name: <?php $fieldValue = $record->getField('Last_Name', 0) ; ?><input type="text" size="30" maxlength="40" name= "<?php echo getFieldFormName('Last_Name', 0, $record, true, 'EDITTEXT', 'text');?>" value="<?php echo $lastname;?>">&nbsp;		 </td> </tr>

<tr><td colspan="2">

<div id="contenttitlebg">

		 <h1>Attach PDF</h1></div></td></tr>						

						

<tr onkeypress="return event.keyCode != 13;">

<td align="right"></td> <td><br>

<!-- Name of input element determines name in $_FILES array -->

<input name="PDFname" type="file" /></td></tr>

	

<!--Display record form controls--><tr><td>&nbsp;</td><td>

<input type="submit" class="buttons" name="-new" value="Submit Application"></td></tr>

</table>

</form>

Link to comment
Share on other sites

This topic is 4351 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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