J_Szwarga Posted February 18, 2020 Share Posted February 18, 2020 Here's my code for using the InputfieldFile in a form on a backend page (Process module) $f = $this->modules->get('InputfieldFile'); $f->name = "mp3_file"; $f->label = "Mp3 Audio File"; $f->extensions = "mp3"; $f->maxFiles = 1; $f->setMaxFilesize("200M"); $form->append($f); For "extensions" I've tried both ".mp3" and "mp3" without the period. The mp3 extension does show up in the form field UI.... But it does NOT limit which files are visible in the "open" dialog box to choose a file to upload... Furthermore, it does not limit which files can be opened and uploaded. Went through the source code and I'm still puzzled why this isn't working as expected. I would expect that the module would use the extensions to add an "accept" property to the input HTML element (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept) But inspecting the html, there is no "accept" property on the resulting input element....and in the source code of InputfieldFile.module, a search for "accept" turns up 0 results.... Anyone have a clue for me? Link to comment Share on other sites More sharing options...
gmclelland Posted February 18, 2020 Share Posted February 18, 2020 The "open" dialog box you see is a Windows only thing. Mac users don't have the same dialog. So it may be working as intended. What happens if you try to upload a pdf file? Does it give you an error? What happens when you upload an mp3 file? Does it give you an error? Link to comment Share on other sites More sharing options...
rastographics Posted February 19, 2020 Share Posted February 19, 2020 No errors, I can upload any file type. The accept parameter is a html web thing, not just a Windows thing, from all indications here:. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept For now I just added the accept attribute manually to the field. I'm surprised this is not done by default? What other functionally does extensions property provide if it doesn't limit what file types can be uploaded? Link to comment Share on other sites More sharing options...
gmclelland Posted February 19, 2020 Share Posted February 19, 2020 Hmm... I'm not sure. Maybe you can check out the code from: You could also check the code from: Ryan also shows an example Hope that helps point you in the right direction. Others here may chime in as well. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now