无法从 drupal7 中的 $_FILES 数组上传文件

Unable to upload file from $_FILES array in drupal7

我正在尝试从 $_FILES 数组上传文件。但在 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.

sites/default/files有权限777

这是我的代码

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);

代码有没有错误?请提出建议。

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

可能应该改为

'public://'

因为它可能已经包含 sites/default/files 路径,如果该路径在 Drupal 设置中设置为 public 文件路径。

编辑: 出于安全原因,文件夹的权限应设置为最宽松的 775。