-3

i want to insert image in oracle database basically that is oci using php ajax and jquery but i dont get any example in internet if someone has a solution please give me. thanks in advance

                        <label for="">Upload Picture : </label>
                      <div class="input-group">
                            <div class="input-group-prepend">
                              <span class="input-group-text"><i class="far fa-image"></i></span>
                            </div>
                              <input  type="file" name="image" id="image">                         
                      </div>
                    </div>


$("#hrm_employeesAddForm").on('click','#addHrmEmployees',function(){
  var dp = $('#image').val();
  $.ajax({
            url  : 'api/Hrm/hrm_employee_api.php',
            type : 'POST',
            data : {action:'imgs',dp:dp},
            success:function(response){
              $("#image").val("");
            }
       })
});


if(isset($_POST['action']) && $_POST['action'] == 'imgs'){
    if(isset($_POST['dp']) || empty($_POST['dp']))
    {
        $dp = $_POST['dp'];
        $image = file_get_contents($_FILES['image_field_name']['tmp_name']);
        $sql = "INSERT INTO COD_EMPLOYEES (EMP_IMAGE) VALUES(empty_blob()) RETURNING EMP_IMAGE INTO :image";
        $result = oci_parse($conn, $sql);
        $blob = oci_new_descriptor($conn, OCI_D_LOB);
        oci_bind_by_name($result, ":image", $blob, -1, OCI_B_BLOB);
        oci_execute($result, OCI_DEFAULT) or die ("Unable to execute query");
        
        if(!$blob->save($image)) {
            oci_rollback($conn);
        }
        else {
            oci_commit($conn);
        }
        
        oci_free_statement($result);
        $blob->free();
}}
  • 1
    We're not a tutorial provider or free write-my-code or do-my-research service, sorry. We'll help you with a specific issue in your code. What have you tried? Where exactly are you stuck? Break the task down...is the Ajax part the problem, or the database query, or something else? You need to be more specific about the issue, and show concrete evidence of a reasonable attempt to solve it yourself. See the [tour], and the [ask] guide for more info. – ADyson Jul 12 '21 at 07:58
  • i just want an example so i can do this task – faisal satti Jul 12 '21 at 09:49
  • Perhaps you do. But that's not what we do at Stackoverflow - read the comment again, and the links I provided. – ADyson Jul 12 '21 at 09:52
  • Anyway I see you've added some code now, which is great - thanks. So what exactly is the issue you're having with that code? Explain a specific problem that we can solve, rather than asking for complete tutorials. – ADyson Jul 12 '21 at 09:53
  • P.S. Looking at the AJAX code, it looks like you need to read https://stackoverflow.com/questions/23980733/jquery-ajax-file-upload-php . Did you do any research on how to upload files with AJAX? It's not hard to find existing information to help you - there are other pages available as well as the one I've just provided. – ADyson Jul 12 '21 at 09:54

1 Answers1

0

Do not store images or files as binary in database. Store them as file in file system and then store the path in database.

Obaydur Rahman
  • 723
  • 5
  • 15