Does anyone know how to return the filename with path for a File Upload field?Nick Amis, Formidable Slack Community
This is a simple question, but the answer is somewhat elusive.
File Upload Field
First, let's gain an understanding of Formidable's file upload field. For one reason or another, the file upload field has had gone through several revisions over the course of its history. In its current incarnation, it uses the popular DropzoneJS library to drive its functionality. DropzoneJS is an open source library that provides drag’n’drop file uploads with image previews. It is lightweight and doesn’t depend on any other library. It's also highly customizable.
When you upload a file through the file upload field, it is immediately uploaded to a directory on your server. Formidable creates its own directory for uploaded files, which you can find under wp-content/uploads/formidable.
When you click the submit button on a form with the file upload field, any uploaded files are added to the WordPress media library. Normally, if you add files to the media library, they are added to the standard WordPress directory structure. But this isn't the case with Formidable's file upload field. Formidable's uploaded files remain in the Formidable directory structure and an entry is created in the wp_posts table for the media library item.
Let's analyze how Formidable manages the database transactions. First, we'll query the wp_frm_item_metas table in PHPMyAdmin and search for a file upload field.
If you're not familiar with Formidable's table structure, see this knowledge base article describing the database schema.
The SQL query returns the following results:
We want to examine the meta value in this result set. The meta value for upload fields is a pointer to the record id in wp_posts that is created the form entry is saved. This means that if we want to retrieve the filename and path, we have to look into wp_posts for the targeted record, and this is what we see:
To find the filename and path, we have to scroll to the right:
The guid, or 'Globally Unique Identifier', contains the filename and path and for this media library entry. In this case, it's:
In order to retrieve the the filename and path for the uploaded article, you have to first get the record id from wp_frm_item_metas, then use that value as the parameter passed to the WordPress get_the_guid() function.
Multiple File Uploads
If you have your upload field configured to "Allow multiple files to be uploaded", the process is a little different because Formidable stores the field's meta_value differently in wp_frm_item_metas. For multiple files, the meta_value is stored as a PHP serialized array:
Serialized arrays need to be unserialized before you can use them. You can then loop through the resulting data set to retrieve each uploaded file's guid.