简体   繁体   English

在 Php(moodle) 中下载所有证书的问题

[英]Problem in down loading all certificates in Php(moodle)

Code to download all certificates:下载所有证书的代码:

    <?php
    require_once('../../config.php');
    global  $DB,$CFG;
    $certlist = $_POST['select_cert'];
    print_r($certlist);  

    $files = array('niBMkaooT.jpg');
    $zip = new ZipArchive();
    $zip_name = time().".zip"; 
    $zip->open($zip_name,  ZipArchive::CREATE);
    foreach ($files as $file) {
      $path = $file;
      if(file_exists($path)){
      $zip->addFromString(basename($path),  file_get_contents($path));  
      }
      else{
      echo"file does not exist";
      }
    }
    $zip->close();
    ?>



      if($certificate!=''){  
          echo "<input type='checkbox' class='checkboxcert' name='select_cert[]' value='$certificate'>";
        }
      echo "</td>";
      echo "<td>";

Also below i am getting $certificate and when i am downloading individual certificates this is working fine.同样在下面,我得到了 $certificate,当我下载个人证书时,它工作正常。 But when selecting multiple document i am not able to download all但是选择多个文档时,我无法下载

    $certificate = get_certificate($userid,$c_id);

Please find the array which i have printed (print_r($certlist))请找到我打印的数组 (print_r($certlist))

Array ( [0] => https://google.com/lms/plufile.php/69402/mod_certificate/issue/484123/Abu 2021_Abu, Neglecting, and Exploitation.pdf [1] =>数组([0] => https://google.com/lms/plufile.php/69402/mod_certificate/issue/484123/Abu 2021_Abu,忽视和利用.pdf [1] =>

Please advise what changes are required?`请告知需要进行哪些更改?`

The certificate PDF isn't always saved, so the file might not always be available证书 PDF 并不总是保存,因此该文件可能并不总是可用

I'd suggest creating and saving the PDF in your own code我建议在您自己的代码中创建并保存 PDF

Have a look at how the PDF is saved in the view code看看 PDF 是如何保存在视图代码中的

https://github.com/mdjnelson/moodle-mod_certificate/blob/master/view.php https://github.com/mdjnelson/moodle-mod_certificate/blob/master/view.php

if ($certificate->savecert == 1) {
    certificate_save_pdf($filecontents, $certrecord->id, $filename, $context->id);
}

Then work backwards from there to see how the variables are created然后从那里向后工作以查看变量是如何创建的

eg.例如。 $USER is the current user $USER当前用户

$certrecord = certificate_get_issue($course, $USER, $certificate, $cm);

So you will need to replace that with the required $user in your code因此,您需要将其替换为代码中所需的$user

$certrecord = certificate_get_issue($course, $user, $certificate, $cm);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM