Viewing file: programX.php (4.07 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
set_time_limit(0);
include_once("../../class/clsConnection.php");
include_once("../../class/clsDB.php");
include_once "../global.php";
include_once "../class/clsSendReceive.php";
include_once "../class/clsCollegeDetail.php";
$oC = new clsConnection($GLOBALS['DBHOST'], $GLOBALS['DBNAME_EOFFICE'], $GLOBALS['DBUSER_EOFFICE'], $GLOBALS['DBPASS_EOFFICE']);
$oTsr = new sendreceive($oC);
$oTsr2 = new sendreceive($oC);
$oTsr3 = new sendreceive($oC);
$oTsr4 = new sendreceive($oC);
?>
<html>
<head>
<title>กำลังดาวน์โหลดเอกสาร</title>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<link href="../source/style.css" rel="stylesheet" type="text/css">
</head>
<body><br><br>
<table width="100%"><tr><td align="center"><b> ---------------------------------- กำลังดาวน์โหลดเอกสาร ----------------------------------</b></td></tr></table>
<?
//----update doc status = r1 to r2
$oTsr3->SearchBytsr_status(r1);
while($oTsr3->GetRecord()){
$oTsr3->Edit();
$oTsr3->tsr_status='r2';
$oTsr3->Save();
}
//----select doc status = r2 start download
$oTsr->SearchBytsr_status(r2);
while($oTsr->GetRecord()){
$tsr_docid =$oTsr->tsr_docid;
$tsr_doc_url=$oTsr->tsr_doc_url;
$tsr_doc_chksum=$oTsr->tsr_doc_chksum;
$tsr_fr_node=$oTsr->tsr_fr_node;
echo " ดาวน์โหลดเอกสาร docid=".$oTsr->tsr_docid."<br>";
if(downloadRemoteFile($tsr_doc_url, "../documentsTmp")==true){
$fileN=substr(strrchr($tsr_doc_url, '/'),1);
$pathfile="../documentsTmp/".$fileN;
$checksum=md5_file($pathfile);
if($checksum==$tsr_doc_chksum){
//if chksum OK -------------update status = r3--------------
$oTsr2->SearchByKey($oTsr->tsr_id);
$oTsr2->GetRecord();
$oTsr2->Edit();
$oTsr2->tsr_status='r3';
$oTsr2->Save();
$tsr_docid2 =$oTsr2->tsr_docid;
$tsr_fr_node2=$oTsr2->tsr_fr_node;
$tsr_id2=$oTsr2->tsr_id_send;
$oTsr2->Close();
//if chksum OK -------------sendTos3-----------------
$oCd = new collegedetail($oC);
$oCd->SearchByKey($tsr_fr_node2);
$oCd->GetRecord();
$msg='?fn=s3&tsr_id='.$tsr_id2;
$path_send='http://'.$oCd->collegeHost.'/mistk/'.'eoffice/admin/sendTSR.php'.$msg;
$res=file_get_contents($path_send);
//if chksum OK --------------set r3 to r4 not wait return fn=s3------------------------
$oTsr4->SearchBytsr_id_send($tsr_id2);
$oTsr4->GetRecord();
$oTsr4->Edit();
$oTsr4->tsr_status='r4';
$oTsr4->Save();
echo '<br>-- ดาวน์โหลดเอกสารสมบูรณ์ --<br>';
}else{
echo '<br>-- เอกสารที่ดาวน์โหลดมาไม่สมบูรณ์ --<br>';
}
}else{
echo '<br>-- ไม่สามารถดาวน์โหลดเอกสารได้ --<br>';
}
echo '-------------------------------------------------<br>';
}
echo "<meta http-equiv='refresh' content='10; URL=programX.php'>";
?>
</body>
</html>
<?
function microtime_float(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function downloadRemoteFile($url,$dir,$file_name = NULL){
if($file_name == NULL){ $file_name = basename($url); }
$url_stuff = parse_url($url);
$port = isset($url_stuff['port']) ? $url_stuff['port'] : 80;
$fp = fsockopen($url_stuff['host'], $port);
if(!$fp){ return false;}
$query = 'GET ' . $url_stuff['path'] . " HTTP/1.0\n";
$query .= 'Host: ' . $url_stuff['host'];
$query .= "\n\n";
fwrite($fp, $query);
while ($tmp = fread($fp, 1024)) {
$buffer .= $tmp;
echo "# ";
flush();
//ob_flush();
}
preg_match('/Content-Length: ([0-9]+)/', $buffer, $parts);
$file_binary = substr($buffer, - $parts[1]);
if($file_name == NULL){
$temp = explode(".",$url);
$file_name = $temp[count($temp)-1];
}
//$file_open = fopen($dir . "/" . date('Y-m-d_His').$file_name,'w');
$file_open = fopen($dir . "/" .$file_name,'w');
if(!$file_open){ return false; }
fwrite($file_open,$file_binary);
fclose($file_open);
return true;
}
?>
|