2

I am using the managed_file in a form to upload a file to Drupal. As you know Drupal saves the name of this file into its database and stores it in the path you give.

Unfortunately, when a user uploads a file which has the filename of a previously existing file, he receives an AJAX error that arises from SQL. Even though Drupal manages to store this file with a different name in the folder, I can't prevent the AJAX error.

Is there a solution for this?

Thanks.

0

As per Drupal structure you need to add option "FILE_EXISTS_RENAME" during save file for example : $file_temp = file_save_data($attachment->data, 'public:///' , FILE_EXISTS_RENAME);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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