I have designed a script which will upload log file data to oracle database. However i want to filter images in my data upload. Here in this case,i don't want my code to upload CLIENT_REQUEST("GET /icons/back.gif HTTP/1.1") having .gif extensions in my request. Can someone please help me with the code.
My LOG file :-
127.0.0.1,-,-,[06/Aug/2018:09:22:02 +0200],"GET /icons/back.gif HTTP/1.1",304,-,"-"
127.0.0.1,-,-,[06/Aug/2018:09:22:02 +0200],"GET /icons/blank.gif HTTP/1.1",304,-,"-"
127.0.0.1,-,-,[06/Aug/2018:09:22:02 +0200],"GET /icons/unknown.gif HTTP/1.1",304,-,"-"
127.0.0.1,-,-,[06/Aug/2018:09:22:02 +0200],"GET /icons/image2.gif HTTP/1.1",304,-,"-"
127.0.0.1,-,-,[06/Aug/2018:09:22:02 +0200],"GET /icons/text.gif HTTP/1.1",304,-,"-"
My php code
<?php
$conn = oci_connect('XYZ', 'XYZxyz1', 'abcdef1/ABC');
if (!$conn) {
$m = oci_error();
echo $m['message'], "\n";
exit;
}
else {
$d = new DateTime();
$yesterday = $d->sub(new DateInterval('P1D'))->format('Y.m.d');
$filename = "access.$yesterday.txt";
$myfile = fopen($filename, "r") or die("Unable to open file!");
while(!feof($myfile)) {
$content= fgets($myfile);
$carray=explode(',',$content);
list($IP_ADDRESS, $USER_IDENTIFIER, $USERID , $REQUEST_TIME , $CLIENT_REQUEST ,$RESPONSE_CODE ,$SIZEOFOBJECT, $COOKIES)=$carray;
$stdii = 'INSERT INTO LOGS(IP_ADDRESS, USER_IDENTIFIER, USERID , REQUEST_TIME , CLIENT_REQUEST ,RESPONSE_CODE ,SIZEOFOBJECT, COOKIES)'.
'values(:IP_ADDRESS, :USER_IDENTIFIER, :USERID , :REQUEST_TIME , :CLIENT_REQUEST ,:RESPONSE_CODE ,:SIZEOFOBJECT, :COOKIES)';
$compiled1 = oci_parse($conn, $stdii);
oci_bind_by_name($compiled1, ':IP_ADDRESS', $IP_ADDRESS);
oci_bind_by_name($compiled1, ':USER_IDENTIFIER', $USER_IDENTIFIER);
oci_bind_by_name($compiled1,':USERID', $USERID);
oci_bind_by_name($compiled1, ':REQUEST_TIME', $REQUEST_TIME);
oci_bind_by_name($compiled1, ':CLIENT_REQUEST', $CLIENT_REQUEST);
oci_bind_by_name($compiled1, ':RESPONSE_CODE', $RESPONSE_CODE);
oci_bind_by_name($compiled1, ':SIZEOFOBJECT', $SIZEOFOBJECT);
oci_bind_by_name($compiled1, ':COOKIES', $COOKIES);
oci_execute($compiled1, OCI_COMMIT_ON_SUCCESS);
}
}
echo "File Uploaded";
oci_close($conn);
fclose($myfile);
?>