Get the filename from the descriptor BFILE : Oracle : Databases PHP Source Code


PHP Source Code » Databases » Oracle »

 

Get the filename from the descriptor BFILE


Unfortunately there is no direct method in PHP to get the filename from
the descriptor. But if you have (or create) an Oracle procedure you could pass it the BFILE
descriptor and get the name.
Instead of executing the query in PHP and using PL/SQL to find the filename, a more
efficient method is to create a PL/SQL anonymous block that does both the query and
extracts the filename from its returned BFILE.

The previous query code in navioo_bfilequery1.php

navioo_bfilequery2.php
<?php
        $c 
oci_connect("hr""hrpwd""//localhost/XE");
        
$s oci_parse($c,
            
'declare '
            
'b_l bfile;'
            
'da_l varchar2(255);'
            
'begin '
            
'select image into b_l from filetest where filenum = :fnum;'
            
'dbms_lob.filegetname(b_l, da_l, :name);'
            
'end;');
        
$fnum 1;
        
oci_bind_by_name($s":fnum"$fnum);
        
oci_bind_by_name($s":name"$name255SQLT_CHR);
        
oci_execute($s);
        
header("Location: http://localhost/tmp/$name");
?>

The filename cj.jpg is returned in $name courtesy of the :name bind variable argument to the
DBMS_LOB.FILEGETNAME() function. The header() function redirects the user to the
image. If you have problems, comment out the header() call and check that $name is valid.
If any text is printed before the header() is output, the HTTP headers will not be correct and
the image will not display.
OCI-Lob


HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Databases
» Oracle