Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
upload complete without log
Browse files Browse the repository at this point in the history
  • Loading branch information
GGJason committed Jul 4, 2016
1 parent 2a247cc commit 0a3362d
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 13 deletions.
Binary file added 1554593_918392864846079_1133049822761146371_n.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 31 additions & 4 deletions csv.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
include("log.php");

//////
// Test File Zone
Expand Down Expand Up @@ -43,9 +42,37 @@ function handleCSV($csvFile){
return;
}

function findTable($schemaName){Weather
switch ($schemaName){
function findTable($schemaName){
}
function getDataNum($fileName,$table){
$file = fopen($fileName,"r");
$max=0;
while (($read = fgetcsv($file,0,",",'"',"\0")) !== FALSE) {
//// For Checking Data
if($read[3]==$table&&$read[4]>=$max)$max=$read[4]+1;
// echo "<br>";
}
fclose($file);
return $max;
}
function getDataZIndex($table,$startTime,$endTime,$type){
$index=1;
while (($read = fgetcsv($table,0,",",'"',"\0")) !== FALSE) {
echo $read[3]." ";
if($read[3]==$type){
if((($read[1]<=$startTime)&&($read[2]<=$startTime))||(($read[1]<=$endTime)&&($read[2]<=$endTime))){
if($read[5]>=$index)$index=$read[5]+1;
}
}
}
return $index;
}
?>








?>
2 changes: 1 addition & 1 deletion log.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//////

function AutoLogger($logType,$action,$logger){
if(!(is_dir("./log/")))mkdir("log",0777);
if(!(is_dir("./log/")))mkdir("log",0771);
$timestamp = "UTC+8 ".date("Ymd_h:i:s")."\t".round(microtime(true) * 1000);
$logFile = fopen("./log/".$logType.".log", "a+");
$log = $timestamp."\t : ".$logger."\t : ".$action."\n";
Expand Down
17 changes: 9 additions & 8 deletions upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@


//////
// Include the Logger Function
// Include the Functions
include ("log.php");
include ("xiData.php");
//
//////

Expand All @@ -20,8 +21,8 @@
$time = time();
$Date = date_create();
$interval=date_format($Date,"ym");
if(!(is_dir("./Uploads/")))mkdir("./Uploads/",0777);
if(!(is_dir("./Uploads/".$interval."/")))mkdir("./Uploads/".$interval."/",0777);
if(!(is_dir("./Uploads/")))mkdir("./Uploads/",0771);
if(!(is_dir("./Uploads/".$interval."/")))mkdir("./Uploads/".$interval."/",0771);
//
//////

Expand Down Expand Up @@ -83,16 +84,16 @@

//////
// Check File Format and Handling.
if($FileType == "jpg" || $FileType == "png" || $FileType == "jpeg" || $FileType == "gif" ) {
if($FileType == "jpg" || $FileType == "png" || $FileType == "jpeg" || $FileType == "gif" ) {
// Image: jpg, png, jpeg, gif
AutoLogger("FILE","File ".$fileName." is checked to be an image with ".$FileType." extention and be record in history.","upload.php/ ");

}

else if($FileType == "csv" || $FileType == "tsv"){
// data: csv,tsv
AutoLogger("FILE","File ".$fileName." is checked to be a data table with ".$FileType." extention and be record in history. Prepare for update to database.","upload.php/ ");

else if($FileType == "csv" || $FileType == "tsv"||$FileType == "CSV" || $FileType == "TSV"){
// data: csv,tsv
AutoLogger("FILE","File ".$fileName." is checked to be a data table with ".$FileType." extention and be record in history. Prepare for update to database.","upload.php/ ");
data($target_file);

}

Expand Down
68 changes: 68 additions & 0 deletions xiData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
//Data, ,xiData/
include("csv.php");
function data($fileName){

if(!(is_dir("./xiData/")))mkdir("./xiData/",0771);
$file=fopen($fileName,"r");
$table=fopen("./xiData/table.csv","a+");

if(stripos($fileName,"weather")){
echo "<br>Weather Data<br>";
insert($fileName,$table,"Weather");
}
else if(stripos($fileName,"Part 1")){
echo "Measure Data Part1<br>";
insert($fileName,$table,"Part 1");
}
else if(stripos($fileName,"Part 2")){
echo "Measure Data Part2<br>";
insert($fileName,$table,"Part 2");
}
else{

}

}

function insert($fileName,$table,$type){
$timestamp = "UTC+8 ".date("Ymd_h:i:s");
$save="./xiData/".$type."_".getDataNum("./xiData/table.csv",$type).".csv";
// copy($fileName,$save);
$min="20000101000000";
$max="20000101000000";

$file=fopen($fileName,"r");
$writeFile=fopen($save,"w+");
// echo fgetcsv($file);
$times=0;
while (($read = fgetcsv($file)) !== FALSE) {
// if($read[0]=="")continue;
// echo "run<br>";
if($type=="Weather"){
$day = explode("/",$read[0]);
$tim = explode(":",$read[1]);
if(count($day)==3)$date = $day[2].$day[1].$day[0].$tim[0].$tim[1].$tim[2];
// echo $date."<br>";
}
else{
$time= explode(" ",$read[0]);
$day = explode("/",$time[0]);
$tim = explode(":",$time[1]);
if(count($day)==3)$date = $day[2].$day[1].$day[0].$tim[0].$tim[1]."00";
}
if($times==1)$min=$date;
else if($date<$min)$min=$date;
if($date>$max)$max=$date;
$write=$date;
for(($i=(($type=="Weather")?2:1));$i<count($read);$i++)$write =$write.",".$read[$i];
$write = $write."\n";
fwrite($writeFile,$write);
$times++;
}
fclose($file);
fclose($writeFile);
fwrite($table,$timestamp.",".$min.",".$max.",".$type.",".getDataNum("./xiData/table.csv",$type).",".getDataZIndex($table,$min,$max,$type)."\n");
// fwrite($table,);
}
?>

0 comments on commit 0a3362d

Please sign in to comment.