将映像保存为Oracle数据库中的BLOB

时间:2018-05-28 05:48:49

标签: android oracle blob

我正在从我的Android应用程序上传图像,并尝试使用PHP将图像作为Blob存储在Oracle数据库中。我使用相同的技术在我的Web应用程序中上传图像,该工作正常。我正在尝试以下代码。需要一些帮助。 TIA

<?php

$conn = oci_connect("test_dev","test_dev","192.168.10.82:1509/testdv");
class emp{}

$image = $_POST['image'];
$name = $_POST['name'];

if (empty($name)) { 
    $response = new emp();
    $response->success = 0;
    $response->message = "Please dont empty Name."; 
    die(json_encode($response));
} else {

      $finfo = finfo_open(FILEINFO_MIME_TYPE);
      $mime = finfo_file($finfo, $image);
      $DIGI_TYPE= $mime;
      $lob = oci_new_descriptor($conn, OCI_D_LOB);

    $myv = file_get_contents($image);   
    $imageProperties = getimageSize($image);
    $lob->writeTemporary($myv, OCI_TEMP_BLOB); 

            $sql = "UPDATE LC_BLOCK_LIST_TECH_PERS
                    SET DIGI_SIGN = :DIGI_SIGN , DIGI_TYPE = :DIGI_TYPE
                    WHERE COM_CODE= '$name'";


    $s = oci_parse($conn, $sql);

    oci_bind_by_name($s, ':DIGI_TYPE', $DIGI_TYPE);
    oci_bind_by_name($s, ':DIGI_SIGN', $lob, -1, OCI_B_BLOB); 
    oci_execute($s, OCI_NO_AUTO_COMMIT);
    oci_commit($conn);
    $lob->close();
    `

1 个答案:

答案 0 :(得分:0)

    <?php

    $conn = oci_connect("DRUG_FINAL","DRUG_FINAL","192.168.10.85:1521/devdb");

    if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
    }

        else{

    echo "connected";   
    }


    $image = $_POST['image'];
    $name = $_POST['name'];

    if(isset($_POST["image"]) && isset($_POST["name"]))
{
    $title = $_POST["name"];
    $image = $_POST["image"];
    $gambar = file_get_contents($image);

     $gambar1 =file_put_contents(base64_decode($gambar1));

    $query = "INSERT INTO images (TITLE, IMAGES) VALUES (:TITLE, EMPTY_BLOB()) RETURNING IMAGES INTO :IMAGES";
    $parse = oci_parse($conn, $query);

    $lob_a = oci_new_descriptor($conn, OCI_D_LOB);

    oci_bind_by_name($parse, ":TITLE", $title);
    oci_bind_by_name($parse, ":IMAGES", $lob_a, -1, OCI_B_BLOB);
    oci_execute($parse, OCI_DEFAULT);

    if($lob_a->save($gambar1))
    {
        oci_commit($conn);
        $lob_a->free();
    }
    else
    {
        oci_rollback($conn);
    }
}