When using MySQL or MariaDB, secure-file-priv option must be disabled in the configuration file.
[mysqld]
secure-file-priv = ""
However, It would be better for the code to work without this modification. The destination folder can be found by requesting the secure_file_priv variable in MySQL.
SHOW VARIABLES LIKE "secure_file_priv";