executing a php script from a different location -


i have php script located in /var/log/myscript.php , want execute /home/user/run. keep getting following errors below. if go directly in folder , run php myscript.php script execute. strange, suggestions. have included script bellow

php notice: undefined variable: f in /var/log/myscript.php on line 73 php warning: fclose() expects parameter 1 resource, null given in /var/log/myscript.php on line 73

             <?php  $host = "some_destination"; $user = "postgres"; $pass = "postgres"; $db = "some_database";  $con = pg_connect("host=$host dbname=$db user=$user password=$pass");    $line = 1;  $files = array(); $dir = opendir('.');   while(false != ($file = readdir($dir))) { if(($file != ".") , ($file != ".."){ $files[] = $file;. } }  natsort($files); // sort.  foreach($files $file){  if ( strpos($file,'syslog.1') !== false ) { echo "\n" .$file;  $f = fopen($file,"r") or exit("unable open file!"); $arr_to_insert = array();   while (!feof($f)) { $group[] = fgets($f); $line = preg_replace('!\s+!',' ', $group[0]);   $arrm = explode(' ',$line);  $month = $arrm[0];   $day = $arrm[1]; $timestp = $arrm[2]; $src = str_replace("src=","",$arrm[11]); $dst = str_replace("dst=","",$arrm[12]); $spt = str_replace("spt=","",$arrm[19]); $dpt = str_replace("dpt=","",$arrm[20]);   if (ctype_digit($day)) { if (ctype_digit($spt)){ if (ctype_digit($dpt)){  $sql = "insert          logs(logmonth,logday,timestp,src,dst,spt,dpt)    values('$month','$day','$timestp','$    $src','$dst','$spt','$dpt')";    $res = pg_query($con, $sql) or die("cannot execute query: $sql\n");    $ar = pg_affected_rows($res);   }  }  }   unset($group);  } }   } pg_close($con); fclose($f);  ?> 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -