Save Submitted PDF Form Data to a File

This article assumes you have the following in place and tested:

Writing the User Data to Disk

This is a relatively simple process. It's no different than writing any other kind of file to disk using PHP's fwrite() function. Simply define the name of the file, where it will be saved to and do the write:

$result_directory = dirname(__FILE__) . '/results';
$xfdf_file = time() . '.xfdf';
$xfdf_file_path = $result_directory . '/' . $xfdf_file;

if( $fp = fopen( $xfdf_file_path, 'w' ) )
{
    fwrite( $fp, $xfdf, strlen( $xfdf ) );
}
fclose($fp);

If everything above was successfulm you now have a new file in the results directory with the XFDF-formatted user-submitted data in it. If you don't have a new file, check the permissions of the directory on the server filesystem to be sure you are able to write to it, and check the PHP warnings and error messages to see what may be causing the problem.

Suggestions or Improvements?

Do you have something that may benefit others regarding what you find on this page? Would you like to share it? If so, simply contact me and I will review it and possibly post it here.

Did this article help you save time for a project? Did this information help you create your website or web application? If so, please send a donation my way - no amount is too small to show your appreciation.