我正处于使用 PHP 开发 SCORM 播放器的初始阶段,所以在任何时候你觉得我做错了,请随时表达你对我的方法的看法,并为开发播放器提供一些帮助。
做完事情之后——
- 创建了一个 zip up loader 来上传我的 zip 文件并将其保存在一个位置。
- 显示提取的 zip 文件。
问题-
按照此链接创建用于播放SCORM
捆绑包的 RTE,但我正在使用jQuery
并window.open()
加载我的包,但我无法api.html
通过当前代码设置文件。该URL直接在框架中播放它,但我以另一种方式进行操作,因此对实现部分几乎没有混淆(如果仍有不清楚的地方,请随时恢复)。
My Full Code
-
目录结构 -
-package(directory to store extracted zip files)
-index.php
-functions.php
-myjs.js
-style.css
索引.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>
函数.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");
})
})