示例#1
0
function GetFileMimeType($Table, $ID)
{
    #-------------------------------------------------------------------------------
    $Path = GetFilePath($Table, $ID);
    #-------------------------------------------------------------------------------
    if (File_Exists($Path['FilePath'])) {
        #-------------------------------------------------------------------------------
        $Mime = FInfo_File(FInfo_Open(FILEINFO_MIME_TYPE), $Path['FilePath']);
        Debug(SPrintF('[system/libs/Upload]: get file type: %s (%s)', $Path['FilePath'], $Mime));
        #-------------------------------------------------------------------------------
        //return Mime_Content_Type($Path['FilePath']);
        return $Mime;
        #-------------------------------------------------------------------------------
    }
    #-------------------------------------------------------------------------------
    return 'application/octetstream';
    #-------------------------------------------------------------------------------
}
 function db_GetValuesCSV($siteCode, $variableCode, $beginTime, $endTime, $methods)
 {
     $validMethods = array();
     //for every method, query the values
     $retVal = "\"time\",\"value\",\"method\"\n";
     foreach ($methods as $method) {
         //values shown in output
         $valuesShownForMethod = 0;
         //locate the file
         $methodCode = $method["MethodID"];
         $methodDescription = $method["MethodDescription"];
         //locate start row
         $methodInfo = db_getMethodInfo($methodDescription);
         $beginRow = 0;
         if (isset($beginTime) && $beginTime != "") {
             $queryBeginYear = substr($beginTime, 0, 4);
             $queryBeginMonth = substr($beginTime, 5, 2);
             $beginRow = ($queryBeginYear - $methodInfo["beginYear"]) * 12 + ($queryBeginMonth - $methodInfo["beginMonth"]);
             $queryBeginDay = substr($beginTime, 8, 2);
             if ($queryBeginDay > 14) {
                 $beginRow = $beginRow + 1;
             }
         }
         //locate end row
         $endRow = 12 * 300;
         if (isset($endTime) && $endTime != "") {
             $queryEndYear = substr($endTime, 0, 4);
             $queryEndMonth = substr($endTime, 5, 2);
             $endRow = ($queryEndYear - $methodInfo["beginYear"]) * 12 + ($queryEndMonth - $methodInfo["beginMonth"]);
             //check for day (db times are for 14th of the month)
             $queryEndDay = substr($endTime, 8, 2);
             if ($queryEndDay < 14) {
                 $endRow = $endRow - 1;
             }
         }
         //this needs to be changed on the server!
         $filepath = GetFilePath() . $siteCode . '/' . $siteCode . '-' . $methodDescription . '.csv';
         if (file_exists($filepath)) {
             $txt_file = file_get_contents($filepath);
             $rows = explode("\n", $txt_file);
             $rownum = 0;
             foreach ($rows as $row) {
                 if ($rownum >= $beginRow && $rownum <= $endRow) {
                     $row_data = explode(',', $row);
                     if (count($row_data) > 1) {
                         $datetime = substr($row_data[0], 0, -1);
                         $dv = substr($row_data[1], 0, -1);
                         $retVal .= "\"" . $datetime . "\",";
                         $retVal .= $dv . ",";
                         $retVal .= "\"" . $methodDescription . "\"\n";
                     }
                 }
                 $rownum++;
             }
         }
     }
     return $retVal;
 }