CommonFunctions::fileexists PHP Method

fileexists() public static method

file exists
public static fileexists ( string $strFileName ) : boolean
$strFileName string name of the file which should be check
return boolean command successfull or not
    public static function fileexists($strFileName)
    {
        if (defined('PSI_LOG') && is_string(PSI_LOG) && strlen(PSI_LOG) > 0 && (substr(PSI_LOG, 0, 1) == "-" || substr(PSI_LOG, 0, 1) == "+")) {
            $log_file = substr(PSI_LOG, 1);
            if (file_exists($log_file) && ($contents = @file_get_contents($log_file)) && preg_match("/^\\-\\-\\-[^-\n]+\\-\\-\\- " . preg_quote("Reading: " . $strFileName, '/') . "\n/m", $contents)) {
                return true;
            } else {
                if (substr(PSI_LOG, 0, 1) == "-") {
                    return false;
                }
            }
        }
        return file_exists($strFileName);
    }

Usage Example

 /**
  * get temperature information
  *
  * @return void
  */
 private function _temperature()
 {
     if (PSI_OS == 'Linux') {
         $hwpaths = glob("/sys/devices/platform/coretemp.*/", GLOB_NOSORT);
         if (($totalh = count($hwpaths)) > 0) {
             $buf = "";
             for ($h = 0; $h < $totalh; $h++) {
                 $tempsensor = glob($hwpaths[$h] . "temp*_input", GLOB_NOSORT);
                 if (($total = count($tempsensor)) > 0) {
                     $buf = "";
                     for ($i = 0; $i < $total; $i++) {
                         if (CommonFunctions::rfts($tempsensor[$i], $buf, 1, 4096, false) && trim($buf) != "") {
                             $dev = new SensorDevice();
                             $dev->setValue(trim($buf) / 1000);
                             $label = preg_replace("/_input\$/", "_label", $tempsensor[$i]);
                             $crit = preg_replace("/_input\$/", "_crit", $tempsensor[$i]);
                             $max = preg_replace("/_input\$/", "_max", $tempsensor[$i]);
                             $crit_alarm = preg_replace("/_input\$/", "_crit_alarm", $tempsensor[$i]);
                             if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && trim($buf) != "") {
                                 $dev->setName(trim($buf));
                             } else {
                                 $labelname = trim(preg_replace("/_input\$/", "", pathinfo($tempsensor[$i], PATHINFO_BASENAME)));
                                 if ($labelname !== "") {
                                     $dev->setName($labelname);
                                 } else {
                                     $dev->setName('unknown');
                                 }
                             }
                             if (CommonFunctions::fileexists($crit) && CommonFunctions::rfts($crit, $buf, 1, 4096, false) && trim($buf) != "") {
                                 $dev->setMax(trim($buf) / 1000);
                                 if (CommonFunctions::fileexists($crit_alarm) && CommonFunctions::rfts($crit_alarm, $buf, 1, 4096, false) && trim($buf) === "1") {
                                     $dev->setEvent("Critical Alarm");
                                 }
                             } elseif (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && trim($buf) != "") {
                                 $dev->setMax(trim($buf) / 1000);
                             }
                             $this->mbinfo->setMbTemp($dev);
                         }
                     }
                 }
             }
         }
     } else {
         $smp = 1;
         CommonFunctions::executeProgram('sysctl', '-n kern.smp.cpus', $smp);
         for ($i = 0; $i < $smp; $i++) {
             $temp = 0;
             if (CommonFunctions::executeProgram('sysctl', '-n dev.cpu.' . $i . '.temperature', $temp)) {
                 $temp = preg_replace('/C/', '', $temp);
                 $dev = new SensorDevice();
                 $dev->setName("CPU " . ($i + 1));
                 $dev->setValue($temp);
                 //                    $dev->setMax(70);
                 $this->mbinfo->setMbTemp($dev);
             }
         }
     }
 }
All Usage Examples Of CommonFunctions::fileexists