January 12, 2018
Image Uploading in Oracle Stored Procedures as a BLOB datatype in PHP
Are you looking for the tutorial to image uploading in oracle ?
Use the below code For Image upload using Oracle stored procedures in PHP.
Simple tutorial for uploading image in blob type to oracle database.
It is simple tutorial for uploading image in oracle database.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
include_once("includes/config.php"); $iResult = -1; echo "Inserted record no: ".$rand = (rand(10,100)); if(@$_POST["btnsubmit"] !="") { if($_FILES["profile_photo"]!="") { print_r($_FILES); $filename = $_FILES["profile_photo"]["name"]; $tmp_filename=$_FILES['profile_photo']['tmp_name']; $tmp_filename1=file_get_contents($_FILES['profile_photo']['tmp_name']); $target_dir = "./testphotos/"; $target_file = $target_dir . basename($_FILES["profile_photo"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); if(isset($_POST["submit"])) { $check = getimagesize($_FILES["profile_photo"]["tmp_name"]); if($check !== false) { echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; } else { if (move_uploaded_file($_FILES["profile_photo"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["profile_photo"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } } echo $filepath = realpath($target_dir.basename( $_FILES["profile_photo"]["name"])); $filepath1 = file_get_contents($filepath); $filepathenc = base64_encode($filepath); } $content = addslashes( file_get_contents($filepath) ); $stmt = oci_parse($conn, "begin tst_blob(:p_f1,:p_f2,:OUT_BLOB); end;"); $objBlob = oci_new_descriptor($conn, OCI_D_LOB); oci_bind_by_name($stmt, ":p_f1", $rand); oci_bind_by_name($stmt, ":p_f2", $rand); oci_bind_by_name($stmt, ":OUT_BLOB", $objBlob, -1, OCI_B_BLOB); oci_execute($stmt, OCI_DEFAULT); $objBlob->savefile($filepath); oci_commit($conn); $objBlob->free(); oci_free_statement($stmt); } |