先開啟學生作品版
2018年1月11日 星期四
2018年1月7日 星期日
2017年12月28日 星期四
CODE_review 巧用 pclzip
pclzip 位於 http://www.phpconcept.net/pclzip/
可以壓縮/解壓縮zip檔
1. opf檔的預視
$archive = new PclZip($path.'/'.$file);
header("Content-type: image/png");
$list = $archive->extract(PCLZIP_OPT_BY_NAME,'Thumbnails/thumbnail.png' ,PCLZIP_OPT_EXTRACT_IN_OUTPUT);
可以壓縮/解壓縮zip檔
1. opf檔的預視
$archive = new PclZip($path.'/'.$file);
header("Content-type: image/png");
$list = $archive->extract(PCLZIP_OPT_BY_NAME,'Thumbnails/thumbnail.png' ,PCLZIP_OPT_EXTRACT_IN_OUTPUT);
PCLZIP_OPT_EXTRACT_IN_OUTPUT 這個選項讓資料直接輸出,這樣就可以用
<img scr = '....php?file=...>方式顯示預視圖
2.如果writer只有一張圖
$archive = new PclZip($path.'/'.$file);
$list = $archive->listContent();
$filename;
for ($i=0; $i<sizeof($list); $i++) {
if (substr($list[$i]['filename'],0,8)=='Pictures') {
$filename = $list[$i]['filename'];
break;
}
}
if ($filename) {
header("Content-type: image/png");
$list = $archive->extract(PCLZIP_OPT_BY_NAME,$filename ,PCLZIP_OPT_EXTRACT_IN_OUTPUT);
}
類似的方法可以把圖顯示出來
3. 顯示sb2檔中的程式碼
$archive = new PclZip($path.'/'.$file);
$json = $archive->extract(PCLZIP_OPT_BY_NAME,'project.json' ,PCLZIP_OPT_EXTRACT_AS_STRING);
$obj = json_decode($json[0]['content']);
foreach($obj->{'children'} as $child) {
echo $child->{'objName'} ;
echo ':<br>';
foreach ($child->{'scripts'} as $script) {
showoneblock($script[2]);
echo "<br><br>";
}
}
function showoneblock($block) {
foreach($block as $b) {
foreach($b as $c) {
if (is_array($c)) {
echo '{<br>';
showoneblock($c);
echo '}';
} else {
echo $c.' ';
}
}
echo "<br>";
}
}
CODE_Review Queue 運用於將網頁靜態化
Queue 最簡單的方式當然就是從尾加進去,從頭拿出來
為了要將一個網站下的所有網頁抓下來,首先第一步就是要把所以要抓的網頁找出來 (檔案應該也是啦)
AddPage('index.html);
While NOT Empty {
$page = get_page();
$urls = parser_page($page);
foreach ($urls as $url) {
if (NOT IN queue) AddPage($url);
}
move pointer to next
}
在Queue中沒有排序,所以要檢查 是否符合 (NOT IN queue) 當網頁數增加很多時,花費的時間就會多。
底下適實作
以$urls為Queue
$urls=array();
加入Queue時檢查是否已在
function addurl($s) {
global $urls;
$s=str_replace('&','&',$s);
if (count($urls)==0) {
$urls[]=$s;
}else {
$find=false;
foreach($urls as $a) {
if ($a==$s) {
$find=true;
break;
}
}
if (!$find) {
$urls[]=$s;
}
}
}
找出網頁中的 url
function findurl($url) {
global $doc, $urls, $sysVar;
$xml = file_get_contents($url);
$doc->load($xml);
$links = $doc->find("a");
foreach ( $links as $l ) {
//echo $l->href.'<br/>';
$href = $l->href;
if ($href == $sysVar['path']) $href= $sysVar['path'].'/';
if ( substr($href,0,7)== ($sysVar['path'].'/') ) {
$ext = substr($href,-4);
if ($ext !='.zip' || $ext !='.pdf' || .....) {
addurl("{$sysVar['protocol']}{$sysVar['host']}".$href);
}
}
}
}
$doc 是由 simple_html_dom() 建立的物件,從 simple_html_dom.php 來的。
為了要將一個網站下的所有網頁抓下來,首先第一步就是要把所以要抓的網頁找出來 (檔案應該也是啦)
AddPage('index.html);
While NOT Empty {
$page = get_page();
$urls = parser_page($page);
foreach ($urls as $url) {
if (NOT IN queue) AddPage($url);
}
move pointer to next
}
在Queue中沒有排序,所以要檢查 是否符合 (NOT IN queue) 當網頁數增加很多時,花費的時間就會多。
底下適實作
以$urls為Queue
$urls=array();
加入Queue時檢查是否已在
function addurl($s) {
global $urls;
$s=str_replace('&','&',$s);
if (count($urls)==0) {
$urls[]=$s;
}else {
$find=false;
foreach($urls as $a) {
if ($a==$s) {
$find=true;
break;
}
}
if (!$find) {
$urls[]=$s;
}
}
}
找出網頁中的 url
function findurl($url) {
global $doc, $urls, $sysVar;
$xml = file_get_contents($url);
$doc->load($xml);
$links = $doc->find("a");
foreach ( $links as $l ) {
//echo $l->href.'<br/>';
$href = $l->href;
if ($href == $sysVar['path']) $href= $sysVar['path'].'/';
if ( substr($href,0,7)== ($sysVar['path'].'/') ) {
$ext = substr($href,-4);
if ($ext !='.zip' || $ext !='.pdf' || .....) {
addurl("{$sysVar['protocol']}{$sysVar['host']}".$href);
}
}
}
}
$doc 是由 simple_html_dom() 建立的物件,從 simple_html_dom.php 來的。
2017年11月27日 星期一
資訊教育競賽學生作品儲存與轉化
1.簡報和繪圖
採用直接上傳的方式,第一次傳,將檔案紀錄於file1欄位,
第二次傳之後,file2=file1,將檔案紀錄於file1欄位
第三次傳之後,刪除file2, file2=file1,將檔案紀錄於file1欄位
總結:
if ($file2 !='') delfile($file2);
$file2 = $file1;
$file1 = uniqueid();
if (第一次上傳) 產生 sort序號 設定初始值
2. 查資料
另用search1, search2資料表儲存學生作答資料
儲存時,將POST資料轉成ans陣列,其中w1,w2為字數,由 javascript 處理
$ans['a1']=$_POST['a1'];
$ans['a2']=$_POST['a2'];
$ans['a3']=$_POST['a3'];
$ans['a4']=$_POST['a4'];
$ans['a5']=$_POST['a5'];
$ans['b11']=$_POST['b11'];
$ans['b12']=$_POST['b12'];
$ans['b13']=$_POST['b13'];
$ans['b21']=$_POST['b21'];
$ans['b22']=$_POST['b22'];
$ans['b23']=$_POST['b23'];
$ans['c1']=$_POST['c1'];
$ans['c2']=$_POST['c2'];
$ans['w1']=$_POST['w1'];
$ans['w2']=$_POST['w2'];
若在work資料表中已存在該生資料
則 $file2=$file1;
$file1 = uniqueid();
$ans[file_id]= $file1
無條件add $ads到 search1
若在work資料表中不存在該生資料
採用直接上傳的方式,第一次傳,將檔案紀錄於file1欄位,
第二次傳之後,file2=file1,將檔案紀錄於file1欄位
第三次傳之後,刪除file2, file2=file1,將檔案紀錄於file1欄位
總結:
if ($file2 !='') delfile($file2);
$file2 = $file1;
$file1 = uniqueid();
if (第一次上傳) 產生 sort序號 設定初始值
2. 查資料
另用search1, search2資料表儲存學生作答資料
儲存時,將POST資料轉成ans陣列,其中w1,w2為字數,由 javascript 處理
$ans['a1']=$_POST['a1'];
$ans['a2']=$_POST['a2'];
$ans['a3']=$_POST['a3'];
$ans['a4']=$_POST['a4'];
$ans['a5']=$_POST['a5'];
$ans['b11']=$_POST['b11'];
$ans['b12']=$_POST['b12'];
$ans['b13']=$_POST['b13'];
$ans['b21']=$_POST['b21'];
$ans['b22']=$_POST['b22'];
$ans['b23']=$_POST['b23'];
$ans['c1']=$_POST['c1'];
$ans['c2']=$_POST['c2'];
$ans['w1']=$_POST['w1'];
$ans['w2']=$_POST['w2'];
若在work資料表中已存在該生資料
則 $file2=$file1;
$file1 = uniqueid();
$ans[file_id]= $file1
無條件add $ads到 search1
若在work資料表中不存在該生資料
$file1 = uniqueid();
$ans[file_id]= $file1
無條件add $ads到 search1
$ans[file_id]= $file1
無條件add $ads到 search1
訂閱:
文章 (Atom)