Question

I am at the initial stage of development of a SCORM player in PHP so at any point you feel I am doing wrong feel free to express your views about my approach and provide some assistance for developing the player.

Following things done -

  1. Created a zip up loader to upload and save my zip files at a location.
  2. Showing the extracted zip files.

Problem-

Following this link to create a RTE for playing SCORM bundle, but I am using jQuery and window.open() to load my package but I am not able to set api.html file via my current code. The URL is directly playing it in a frame but I am doing it in another way so little confused about the implementation part(feel free to revert back if somethign still unclear).

My Full Code -

Directory Structure -

-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");
    })
})
Was it helpful?

Solution

Okay, so you uploaded the files, unzipped them and launched in a window. Assuming the files are really a scorm package, they will try to send AJAX POST requests to your server. You have to be ready to catch those requests and process them accordingly, e.g. read/write data from/to database. Do you have that part coded?

This is NOT an easy thing to code. Good guys at rustici.com did all heavy lifting and created a SCORM Engine that you can buy and use. Of course, it'll cost you (dearly).

Link for the Engine: http://scorm.com/scorm-solved/scorm-engine/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top