0

I can't figure out what is wrong with this code for file uploads. I am trying to specify multiple extensions for the file upload - it works with a single extension, but if I specify more, it fails and only accepts the last item in the list, even though the error message appears to be self-contradicting. If no extensions are specified the system default list works correctly, but I need to add some extensions.

I am enclosing the minimal code, since after trying everything, modifying this code was the only difference between success and failure:

This works (regardless of the extension)

$file = file_save_upload('sequencefile', 
    array(
             'file_validate_extensions' => array('seq')));

This fails on 'jpg', but works on 'seq'; moving jpg to the end of the list works for jpg, but then fails for the others.

$file = file_save_upload('sequencefile', 
     array(
             'file_validate_extensions' => array('jpg, jpeg, png, gif, txt, doc, docx, ab1, seq')));

The error message on a jpg file is as follows, even though jpg is clearly in the list:

"The specified file mbpdpermissionsP2.jpg could not be uploaded. Only files with the following extensions are allowed: jpg, jpeg, png, gif, txt, doc, docx, ab1, seq."

What am I missing? it should be very simple and yet I can't get it to work.

thanks!

1 Answer 1

1

Don't use a comma separation, separate extensions just with space

'file_validate_extensions' => array('jpg jpeg png gif txt doc docx ab1 seq')));
2
  • To better explain, $validators is an array keyed by callback functions. Thus the member $validators['file_validate_extensions'][0] will be passed to the function file_validate_extensions( &$file, $extensions which is expecting: $extensions: A string with a space separated list of allowed extensions. Always check the API.
    – Triskelion
    Mar 26, 2013 at 22:06
  • Thank you so very much! I knew a different pair of eyes would have seen it
    – user14760
    Mar 28, 2013 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.