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

时间:2016-10-01 12:31:53

标签: file upload drupal-7

我正在尝试从$_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);

代码中有错误吗?请建议。

1 个答案:

答案 0 :(得分:1)

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

应该改为

'public://'

因为它的probaby已包含sites/default/files路径,如果该路径在Drupal设置中设置为公共文件路径。

编辑: 出于安全原因,应将文件夹的权限设置为最高允许775。

相关问题