Fileupload filename not being sent of form submit

Status
Not open for further replies.

achartier

Administrator
Staff member
I am trying to validate the filename in a php validation plugin but $data is not set to the filename on submit. I threw in some debug in the code back up the chain to components/com_fabrik/controllers/form.php and it does not appear the elements input data is being sent in the post.

You can see the behavior at my ALG-Mexico site. Once logged in got to menu Club Administration and under Committees choose Document Upload.

Site details: J2.5.22, Fabrik 3.2 at latest github.
 
Yes, it seems php validation is not working with fileupload (nor simple ($data is empty) nor ajax ($data is array of array).
Rob/Hugh?
 
Just to confirm expectations while I look at this ... are you expecting a filename every time, or just when a new file is being uploaded?

-- hugh
 
OK ... I'm pretty sure this has always been the case. The file upload element is ... different, to say the least.

I've made a start on attempting to make the newly uploaded filename available in $data, in this commit:

https://github.com/Fabrik/fabrik/commit/0aee076536fbd90b805311bfe80cee962b31d92f

... but because this is very much experimental code that could have unforeseen side effects, I've disabled that new funciton by addinf _off to it. So to test, you'll need to do a github update, then edit that file, and remove the _off from that new function name.

It *should* then add the filename for a newly uploaded file into the form's data before validation. However, this could well break other aspects of the element, so test it well!! And it'll only work right now on simple (non AJAX) uploads in non-repeat groups.

Your alternative, if this doesn't work or you need AJAX or repeat groups, is to access the superglobal $_FILES[] array directly, which is where PHP write the data of uplaoded files to ... like the name, the obfuscated name, the size, upload location, etc. So for a simple upload, the name would be in $_FILES['yourtable___yourelement']['name']. For repeat groups with simple uploads, that would be an array. For AJAX uploads ... well, I can't recall. And for AJAX ina repeat group ... I don't even want tot hink about it!

-- hugh
 
OK, but before you go to too much work here I am looking for the filename in a validation before it is uploaded. Based on your comments above it looks to me like this will happen after the file is uploaded.

For further clarification what I really want is to ensure no duplicate filenames. The isunique validation ensures there is no duplicates in repeating groups, but I don't want to upload a file that already exists on the server. I would be quite happy if there was an option in the "If existing image found" dropdown to "Duplicates not allowed" or some such. My preference of course would be that the file not be uploaded at all in this case for bandwidth, time and security reasons but could live with it if necessary.
 
With the option"If existing image found?"= "Keep original file" you have the validation you are looking for. If you are trying to upload the same file you'll get a validation error "file already exists".
 
I guess I will have to test that again. I think the reason I was trying to perform this check in the php validation plugin was because I must have had problems with this selection. I will try again and see what results I get.
 
Just FYI, that's one of the reasons the upload element is a bit different. For instance, AJAX validation won't typically work, because the file simply isn't uploaded until the form is submitted - that's an HTML forms thing, not a Fabrik thing - and uploading happens before Fabrik ever gets invoked (actually, before J! even gets instantiated). So even if you put an AJAX validation on an upload element, we won't know anything about the actual file. So there's not really any way of preventing an upload to "save bandwidth", short of writing your own JavaScript, which would detect an "on change" of the form input DOM element, grab the filename from it, make an AJAX call to the server ... yada yada.

Even then ... you may want to do your own checks and tests, for instance ... is it really the same file? Two files called foo.pdf could well be entirely different, so you may want to run a checksum test on the new upload and the existing file. Etc.

-- hugh
 
Not sure it's time wasted, somebody else is probably going to be asking for the same thing at some point. I have not tested Troesters recommendation yet, been busy fighting css and template issue. I will get back to this. Hopefully today.
 
I can confirm Troesters recommendation works. I must have had trouble with this previously which is why I wanted to validate in the php plugin.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top