用PHP构建SCORM播放器

Building a SCORM Player in PHP

本文关键字:播放器 SCORM 构建 PHP      更新时间:2023-09-26

我正处于PHP中SCORM播放器开发的初始阶段,因此在任何时候,如果你觉得我做错了,请随时表达你的对我的方法的看法,并为培养球员提供一些帮助。

完成以下事项-

  1. 创建了一个zip加载程序来上传并保存我的zip文件
  2. 显示提取的zip文件

问题-

按照此链接创建用于播放SCORM捆绑包的RTE,但我正在使用jQuerywindow.open()加载我的包,但我无法通过当前代码设置api.html文件。URL是直接在一个框架中播放的,但我是用另一种方式来做的,所以对实现部分没有什么困惑(如果有些东西还不清楚,请随时回复)。

My Full Code-

目录结构-

-package(directory to store extracted zip files)
-index.php
-functions.php
-myjs.js
-style.css

index.php

<?php
include 'functions.php';
if( isset($_FILES['fupload']) && isset($_POST['submit']) ) {
    $filename = $_FILES['fupload']['name'];
    $source = $_FILES['fupload']['tmp_name'];
    $type = $_FILES['fupload']['type']; 
    $name = explode('.', $filename); 
    $target = 'package/' . $name[0] . '-' . time() . '/';  
    // Ensures that the correct file was chosen
    $accepted_types = array('application/zip', 
                                'application/x-zip-compressed', 
                                'multipart/x-zip', 
                                'application/s-compressed');
    foreach($accepted_types as $mime_type) {
        if($mime_type == $type) {
            $okay = true;
            break;
        } 
    }
  //Safari and Chrome don't register zip mime types. Something better could be used here.
    $okay = strtolower($name[1]) == 'zip' ? true: false;
    if(!$okay) {
          die("Please choose a zip file, dummy!");       
    }
    mkdir($target);
    $saved_file_location = $target . $filename;
    if(move_uploaded_file($source, $saved_file_location)) {
        openZip($saved_file_location);
    } else {
        die("There was a problem. Sorry!");
    }
}
?>
<!DOCTYPE html> 
<html>
  <head>
    <title>How to Upload and Open Zip Files With PHP</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="style.css" />
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="myjs.js"></script>
  </head>
  <body>
    <div id="container">
    <h1>Upload A Zip File</h1>
    <form enctype="multipart/form-data" action="" method="post">
        <input type="file" name="fupload" /><br />
        <input type="submit" value="Upload Zip File" />
    </form>
    <div class="show-files">
    <ol>
        <?php
        $dir = new DirectoryIterator('course');
        foreach ($dir as $fileinfo) {
        if (!$fileinfo->isDot()) {
        echo '<li>', '<span class="packagename">',$fileinfo->getFilename(), '</span>','<span class="play"><button id="',$fileinfo->getFilename(),'">Play</button></span>','</li>';
        }
        }
        ?>
    </ol>
    </div>
    <!--
    <iframe id="frame" src="" width="100%" height="300"></iframe>
    -->
    </div><!--end container-->
  </body>
</html>

functions.php

<?php
function openZip($file_to_open) {
    global $target;
    $zip = new ZipArchive();
    $x = $zip->open($file_to_open);
    if($x === true) {
        $zip->extractTo($target);
        $zip->close();
        unlink($file_to_open);
    } else {
        die("There was a problem. Please try again!");
    }
}
?>

myjs.js

$(document).ready(function(){
    $('button').on('click',function(){
        var myid = $(this).attr('id');
        var url = "http://mysite/package/"+ myid +"/index.html";
        //$("#frame").attr("src", url);
        window.open(url,"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
    })
})

好的,所以您上传了文件,解压缩了它们,并在窗口中启动。假设这些文件真的是一个scorm包,它们将尝试向您的服务器发送AJAX POST请求。您必须准备好捕获这些请求并相应地处理它们,例如从数据库读取/向数据库写入数据。你把那个零件编码了吗?

这不是一件容易编码的事情。rustici.com上的好人做了所有繁重的工作,创造了一个你可以购买和使用的SCORM引擎。当然,这会让你付出(高昂的)代价。

发动机链接:http://scorm.com/scorm-solved/scorm-engine/