change_comcfg.php 1.01 KB
<?php
 //include('../cfg/file_name.php');

  $open_file = '/home/pi/Desktop/vAlert/bin/vAlert8Common.cfg';
  shell_exec("sudo chmod 777 ".$open_file);
  $versionTXT='version.txt';
  
  $handle2 = @fopen($versionTXT,"r");
 //讀檔案
 $Device=array();
 while(($data = fgetcsv($handle2,1000,"\n")) != false){
  foreach($data as $key => $value){
   if($value != ""){
    $Device[]=$value;
   }
  }
 }
  
 switch ($Device[0]) {
  case 'Palert Plus S3':
   
  break;
  
  case 'Palert Plus':
    $mypost=explode("\n",$_POST['config']);
    $source=explode("\n",$_POST['source']);
    $index=0;
    $diff=array_diff($source,$mypost);
    //$handle=fopen($open_file_test,'w') or die("cannot open file");
    //var_dump($source);
     for($i=0;$i<count($source);) {
      $source[$i]=$mypost[$index];
      $index++;
      $i++;
     }
     $inputStr=implode("\n",$source);
     //echo $inputStr;
     file_put_contents($open_file,$_POST['config']);
  break;
  
  default:
   echo 2;
  break;
 }
?>