<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
//include('../../db.php');
extract($_REQUEST);
$ret_msg = 0;
$arr = json_decode($msg, true);
$data = rawurldecode($arr['data']);
$date = date('d-M-y H:i:s');
$date = strtoupper($date);

$connection = oci_connect('hidm', 'Hdm$436#', '172.31.11.41:1521/hidb');
$sql = "INSERT INTO SITE_PAYMENT_DOC_STORAGE (NAME,MIME,DATE_TIME,DATA) VALUES('".$arr['name']."','".$arr['mime']."',TO_DATE('$date','DD-MON-YY HH24:MI:SS'), empty_blob()) RETURNING DATA INTO :DATA";

$result = oci_parse($connection, $sql);
$blob = oci_new_descriptor($connection, OCI_D_LOB);
oci_bind_by_name($result, ":DATA", $blob, -1, OCI_B_BLOB);
oci_execute($result, OCI_DEFAULT) or die ("Unable to execute query");

if(!$blob->save($data)) {
    oci_rollback($connection);
	$ret_msg = 0;
}
else {
    oci_commit($connection);
	$ret_msg = $arr['name'];
}

oci_free_statement($result);
$blob->free();
oci_close($connection);
echo $ret_msg;
?>