#1 July 21, 2016 12:38pm

Registered: March 17, 2015
Posts: 3

Form Builder - File Upload Handling

We are working with a form that has a file upload and wanting to accomplish three things:

1. We want to limit the file type that can be uploaded.
2. We want the files to be removed from the server, presumably when the entry is deleted. We noticed it is not removed when the entry is removed.
3. Control of the file size (within server limitations of course). We do see the form obeys (as it has to) the server upload limit.

If this is something you advise we handle, knowing any hooks or caveats would help a good deal. Thank you.


#2 July 21, 2016 3:26pm

From: Baltimore, MD
Registered: April 2, 2012
Posts: 925

Re: Form Builder - File Upload Handling

I'd probably build a custom field type for that.

1. Make a custom drawing file that mostly is a copy of /core/admin/form-field-types/draw/upload.php but sets the <input>'s accept property to filter out the file types you don't want.

2. Start off with a custom processing file that looks up the existing form entry (via $_POST["id"]) to see if it has an existing file. Then include the /core/admin/form-field-types/process/upload.php file so that it handles the bulk of the operation. Then check if $field["output"] is different from what you looked up earlier. If it is, use the BigTreeStorage class' delete method to delete the old file.

3. You can't really control file sizes other than checking in your process file to see if it was too large. The HTML MAX_FILE_SIZE that is drawn doesn't really do much as it's easily changed by the user and some browsers completely ignore it. You could use Javascript to create your own <input> replacer that checks file sizes and throws errors client side if it's important a user knows before uploading.


Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.