【问题标题】:moodle 2.7 filemanager issuemoodle 2.7 文件管理器问题
【发布时间】:2023-03-28 21:46:01
【问题描述】:

我正在与moodle 2.7 中的表单的文件管理器合作。

保存和上传文件功能很好。

我需要确定文件管理器对象当前是否包含文件。

这是我尝试过的:

if($draftitemid = file_get_submitted_draft_itemid('attachments')){ 
   $A=1; 
}else{ 
   $A=2; 
}

但它总是返回 1;

【问题讨论】:

    标签: moodle file-manager


    【解决方案1】:

    [已解决] 在保存表单文件之后和更新记录之前我使用:

    $fs = get_file_storage();
    $files = $fs->get_area_files($context->id, $component,$path, $itemid,'',false);
    if(!empty($files){
     $A=1;//have files
    }else{
     $A=2;//No files
    }
    

    这对我有用。

    【讨论】:

      【解决方案2】:

      这一行:

      $draftitemid = file_get_submitted_draft_itemid('attachments')
      

      $draftitemid 设置为file_get_submitted_draft_itemid('attachments') 返回的值。在if 语句中,设置变量的结果始终为true。因此,这是一个错字,您想要的是:

      if($draftitemid == file_get_submitted_draft_itemid('attachments')){ 
      

      【讨论】:

        猜你喜欢
        • 2014-12-07
        • 1970-01-01
        • 1970-01-01
        • 2014-04-02
        • 1970-01-01
        • 2018-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多