Recently I have been trying to process files uploaded via Dropzone.js in Drupal. I am not using the Drupal API form stuff, just a plain HTML code to generate Dropzone, but I want to process uploaded files using Drupal functions (file_save_upload(), in particular). However, I am not able to "catch" the uploaded file using the function.
For some reason, the $_FILES array generated by Dropzone, looks like this:
Array (
[files] => Array
(
[name] => 5bcb9c.jpg
[type] => image/jpeg
[tmp_name] => /private/var/tmp/phpgZHmT8
[error] => 0
[size] => 273794
) )
However, Drupal's function file_save_upload() is awaiting the $_FILES array in this structure:
Array
(
[files] => Array
(
[name] => Array
(
[files] => 5bcb9c.jpg
)
[type] => Array
(
[files] => image/jpeg
)
[tmp_name] => Array
(
[files] => /private/var/tmp/php4ebqBs
)
[error] => Array
(
[files] => 0
)
[size] => Array
(
[files] => 210075
)
)
)
so what I had to do was to change the $_FILES variable (yes, I know!) so it matches the structure required by Drupal. It works now, although I do not quite understand why Dropzone generates another structure and Drupal requires other structure of the $_FILES variable. If anyone can elaborate on this, I would be glad. Nevertheless, my solution works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With