Devidas Kadam
Devidas Kadam

Reputation: 944

Unable to upload file from $_FILES array in drupal7

I am trying to upload file from $_FILES array. but getting following error in drupal7.

The specified file temporary://fileOYnPHK could not be copied, because the destination directory is not properly configured.
This may be caused by a problem with file or directory permissions. More information is available in the system log.

The sites/default/files has permissions 777

Here is my code

if($_FILES['files']['name']['field_tenant_review_ref_und_form_field_tenancy_document_und_0']){
    $file_path = file_save_data(file_get_contents($_FILES['files']['tmp_name']['field_tenant_review_ref_und_form_field_tenancy_document_und_0']),
    'public://sites/default/files/'.$_FILES['files']['name']['field_tenant_review_ref_und_form_field_tenancy_document_und_0']);
   }
   //$tenant_review->field_tenancy_document->file->set($file_path);

Is there any mistake in code? Please suggest.

Upvotes: 0

Views: 57

Answers (1)

Emil Carpenter
Emil Carpenter

Reputation: 2149

'public://sites/default/files/'

should probably be changed to

'public://'

because it probaby already contains the sites/default/files path, if that path is set in Drupal settings as the public files path.

Edit: The permissions for the files folder shoud be set as most permissive to 775 for security reasons.

Upvotes: 1

Related Questions