Saving a file to a BLOB and back...

Hello everyone.
I'm trying to save a file to a blob, and recover the blob value later to save to a file, but i'm having problems.
I'm recording and retrieving the data sucessfuly, but the file written is like corrupted. But it is with the same filesize as the original one.
This is how i'm doing:
Recording the file to the database (BLOB):
<?
$conn = oci_connect('USER_NAME', 'PASSWORD', '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MYSERVER)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=MYSERVICENAME)))');
$filePath = '/var/www/html/Something.png';
$fileOut = '/var/www/html/fileback.png';
$codigo = 5;
$blob = oci_new_descriptor($conn, OCI_D_LOB);
$sql =
"begin
   insert into MYTABLE (COD, FILE) values (:COD, :FILE);
exception
  when dup_val_on_index then
     update MYTABLE set FILE = :FILE where COD = :COD;
end;";
// Parse the query
$stid = oci_parse($conn, $sql);
// Bind values
oci_bind_by_name($stid, ":COD",  $codigo);
oci_bind_by_name($stid, ":FILE", $blob, -1, OCI_B_BLOB);
// Get the file
$file = fopen($filePath, 'rb');
// Read file content
$fileContent = fread($file, filesize($filePath));
// Write file content to the BLOB
$blob->writeTemporary($fileContent);
// Execute the statement
$r = oci_execute($stid, OCI_DEFAULT);
// Commit
oci_commit($conn);
// Close BLOB descriptor
$blob->close();
// Release the statement and close the connection
oci_free_statement($stid);
oci_close($conn);
Retrieving the BLOB value:
$conn = oci_connect('USER_NAME', 'PASSWORD', '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MYSERVER)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=MYSERVICENAME)))');
$filePath = '/var/www/html/Something.png';
$fileOut = '/var/www/html/fileback.png';
$codigo = 5;
$sql = 'select * from MYTABLE where COD = :COD';
$stmt = oci_parse($conn, $sql);
oci_bind_by_name($stmt, ":COD", $codigo);
$result = oci_execute($stmt);
$a = oci_fetch_array($stmt, OCI_RETURN_NULLS);
$a['FILE']->export($fileOut);   // Don't work
//file_put_contents($fileOut, $a['FILE']->read($a['FILE']->size()), FILE_BINARY);   // Don't work
//file_put_contents($fileOut, $a['FILE']->load(), FILE_BINARY);   // Don't work
fwrite(fopen($fileOut, 'rwb'), $a['FILE']->load());
oci_close($conn);If someone can help me with anything i appreciate, thanks.
Edited by: user1977051 on 12/06/2009 10:33

I solved it.
The problem is because the execute after the blob write:
// Write file content to the BLOB
$blob->writeTemporary($fileContent);
// Execute the statement
$r = oci_execute($stid, OCI_DEFAULT);and should be:
// Execute the statement
$r = oci_execute($stid, OCI_DEFAULT);
// Write file content to the BLOB
$blob->writeTemporary($fileContent);
// i'm using this instead
$blob->saveFile($filePath);Thanks.

Similar Messages

  • Using iPhoto 09, 8.1.2 How do I re-route saving pictures to the hard drive? Currently am saving to files on 'my' partition, and would like to change to save to a shared file so both partitions can view and access.

    Using iPhoto 09, 8.1.2 How do I re-route saving pictures to the hard drive? Currently am saving to files on 'my' partition, and would like to change to save to a shared file so both partitions can view and access.

    Drag the Library from the Pictures folder to the Users/Shared folder. I would point out that folks doing this on 10.6 and later frequently meet permissions issues. You might do better moving it to an appropriately formatted External Disk.

  • Move a file to another computer and back and keep links from breaking?

    I have a high school kid neighbor who is going to work on some pages that are on my site, but she does not have the site or access to the server.  I want to give her the page on a thumb drive to work on in Dreamweaver on her computer. The pages have links and graphics already in them that work.  After she updates the words on the page, I want to then get it back from her and put it back into my local disk version. 
    When I tried this, all the existing  links to the images were broken when I copied her page back into my local Dreamweaver site folder .  How should I move the page to her computer and back so that when I get it back the image and other links that were valid when I gave it to her are still valid?  Using the Mac's Operating system file manager isn't the answer it seems.
    Thanks
    Hank

    Hi Hank,
    one possibility would be your school kid neighbor generates by using a file manager a directory tree that is a mirror image of your tree. For example:
    So the respective links should be identical.
    Hans-G.

  • How can i restore my e-mails (especially a saved message file) after i uninstall and reinstall

    I have picked up some kind of bug in my e-mail program. I have used malwarebyte and Norton and I think it is cleared up. the problem is that I now cannot send e-mails. Comcast tells me the problem is in thunderbird and I should uninstall and reinstall. I have a "saved message file" I do not want to lose. where is this file and how can I save it. thanks.

    Please tell comcast from me that they are idiots.
    The suggestion to uninstall and reinstall is about as likely to fix your issue as dropping the device in the bath.
    So lets look at this. I assume you get some sort of error message, what is it? Exactly please.
    Personally I would be putting money on Nortons being the issue as it has a very long standing habit of making mail sending and receiving difficult.
    Check in the Nortons firewall that Thunderbird has full access to the internet. Automatic is not enough. Then disable all email scanning ion Nortons, reboot your computer and try sending again. Any better? A new error message?

  • I am looking for a way to convert Microsoft Office files to my apple and back again

    I am looking for a way to convert Microsoft Office files to my apple and vise vera.
    <Re-Titled By Host>

    you are asking about Microsoft products and using a laptop, not a workstation Mac Pro.
    The Numbers and Pages Apple Communities. or MS Community if you want those.
    Importing and Exporting, but Numbers and Pages will not do a SAVE into other formats by default, and therefore have to keep using Export which is messy.
    Changing your own thread midstream may not be ['thread hijack'] but it is like having the rug pulled out by changing the subject on us.

  • Missing files after powering down and back up

    I turned off my new Air for the first time in weeks. When I powered back up I was and am missing alot of  open office documents and pictures I had downloaded and saved. Please help these aren't files I can lose.

    Voice command or Voice over?  Two different things.  Voice command can not be disabled, Voice over can.
    Have you tried a restore from backup or as new?

  • I have a problem when cropping 8 but tiff files in elements 12. Once area is selected and I crop the image it disappears. The file no. sill shows but the image is not viewable. I have saved the file from that point and tries reopening but the image isn't

    Has anyone experienced this before ? I have previously been able to crop images with no problem. Recently when I open an image and crop it and confirm the action the image 'disappears' If I save and go to reopen the file is there but it will be  zero meg in size.

    Hi,
    Try resetting the crop tool.
    To the right of the tool option bar, click on the little horizontal lines and you should see reset tool option.
    Good luck
    Brian

  • Saving ai file with title, description and keywords to jpg

    Hi,
    Is ther a way to save an ai file to eps and jpg   including the document title, the description and keywords in the xmp file info?
    JPD

    Hi,
    I was wondering if I can get the Description and keywords from an ai file
    then
    add theese to a created jpg or eps with something like this:
    ---snip     SaveForStocks-10.js version 1.1 ---
      // Export as a jpg
      targetFile = new File(destFolder + '/' + name1);
      Doc.exportFile( targetFile, fileType, jpgExportOpts );
    --- snip---
    ---snip     http://forums.adobe.com/thread/478694?tstart=60 --
    #target bridge
    addNametoMeta = {};
    addNametoMeta.execute = function(){
      var sels = app.document.selections;
      for (var i = 0; i < sels.length; i++){
    var md = sels[i].synchronousMetadata;
        md.namespace = "http://ns.adobe.com/photoshop/1.0/";
        var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$/, '');
        md.Keywords = md.Keywords +  ";" +  Name;
    ----- snip----

  • Saving video files in iMovie'11 and iMovie'06

    Hi gang! I have a question about iMovie.
    When I bought an iMac in 2006 it came with iLife06 preinstalled. Ever since then I have been using iMovie 06 to make movies. In the fall of 2007 I bought a video camera and I started filming my floorball team's games. If you want to find out more about floorball, check out this link:
    http://en.wikipedia.org/wiki/Floorball
    Anyway... Since then I have been making little clips and posted them on Youtube, much to te enjoyment of the players. I have also burned every single game I've filmed on a DVD. What I have done also is save certain clips, highlights, i.e. goals and saves and such. I have on iMovie project save for each season since then. 2007/08, 2008/09, 2009/10 and about half of the 2010/11 season. We're talking of about 800-900 clips.
    Now...
    About two weeks ago the harddrive on my trusted old iMac died on me. Fortunately I had the material backed up on an external harddrive. I bought a new computer, a Mac Mini. Luckily I had iMovie 06 on the external drive so I could still use it, should I want to (I preferred its interface to that of iMovie 08).
    However, I edited the film from our last game in iMovie'11, and I am smitten. Which leads me to my question.
    How do I continue to save my highlight clips? The goals and the saves and whatnot? Should I save them in Events or in Projects?

    Thanks for the feedback guys.
    The keyword feature sounds very handy. In the old iMovie 06 I gave each clip I save a number/name. four digits depending which season it was (0809 for the 2008/09 season for example) - then three digits (001 for the first one, 002 for the second one, 003 for the third one etc.) and then I enter the name of the person who scored the goal or made the save. 1011-091 Oskar Andersson, 1011-135 Bobby Ehnberg, for example. If I can tag the new clips with keywords in the same manner that will be very useful later, if I should happen to make a film with only goals that Bobby has scored for example.
    I'm amazed how smooth iMovie'11 is, once you get a hang of how to edit your films. And it's so easy to make cool clips.
    http://www.youtube.com/watch?v=tr-bfXLWDv0&feature=related
    http://www.youtube.com/watch?v=r5HTx1X8gas
    http://www.youtube.com/watch?v=lsZEy2Wxa-8
    The trailers you can make are awesome!

  • Can I get back a file that logic deletes... Well I did but I had thought I saved the file under a different name?

    Hi. I have been using logic pro on the computer at music school... A Mac pro... Anyway, I was recording a friends band. W got some awesome takes down. I was then doing a little post, saved the file as one name and then stared working on it under a new file name. Anyway, logic came up with a splash that asked if I would like to delete the original file, and I clicked yes, as I thought I had saved the session under a different name just earlier. Anyway, I lost everything. Ok... Shirt I thought... But I managed to find everything in the recycle bin. Except one awesome take of an awesome song, I am a little bit heart broken as I've gone though the sessions undo file in quite some detail, but I seem to have lost it. I have access to the file on my Mac at home (MacBook pro, and logic express 8 I think) cool that I can open logic pro files in logic express, but anyway. Anyone want to offer me any solace? I think a solution might be too much to ask for....

    If you were using OSX 10.7 then you could go back to a previous version, but you have overwritten the file.
    Peter

  • Uploading XL file using call Transaction and running in back ground

    Hi all,
       I am updating the T-code VA01 using call TRansaction method ....
      i am uploading the file is XL file for that i m using the FM ALSM_EXCEL_TO_INTERNAL_TABLE.
      But if execute my program in the back ground This FM is giving Dump because it can not Execute in Back GRound...
      Plz let me know any FM to upload data from Excel file Both from foreground and back ground....
      Plz let me know ASAP..
    Thanks,
    Suresh

    HI...,,
    When u run any program in Background, it will not have any contacts with the presentation server.... You cannot upload  a presentation server file..
    But u can use the Application server file...
    SO first store this excel file's data in Application server using the transaction CG3Z and then use the Open data set and read dataset to upload the application server file !!!
    reward all helpful answers !!
    regards,
    sai ramesh

  • Web browser for running locally saved html file with Marquee Text

    I have a html file contain Marquee text.
    I want to display that html file in oracle forms(10g).
    I already use simple html browser but it does not support marquee text.
    I already tried to convert the html file into Gif file but Marquee text not appear in gif file.
    Is there any browser which support the locally saved html file with marquee text and also it can be embedded in oracle form.
    Or is there any way for display that html file within the oracle forms.
    Remember I don't want to display that file in separate window.I want to display that html file within the form.
    Regards

    Actually that is what I was doing last night and got a bad flash and bricked my router..so its on its way back to Linksys...

  • When saving a File OS Is Creating Multiple Folders With The Same File Name

    Not sure what I changed but, now when I save a any file (ppt. word, Keynote,Pages e.g.,) to the desktop or any other location the OS will also create multiple file folders with the same file name as the file I'm saving. Inside the folders are what appears to be files locating the saved files. What can I do to fix this problem?
    I'm using the 10.7.2 version
    MacBook Pro

    Misio wrote:
    It looks like a finder bug. To replicate, I surf to any website, I right-click on a jpg image, select "Save Image As" and in the window that pops up I type in the filename "000.jpg", I select the folder Pictures, and click on Save.
    BTW, I don't know why, but the file was saved only as "000" without the file extension ".jpg". Does anybody know why?
    the extension is simply hidden. go to the get info panel for the file and uncheck the option to hide the extension.
    Then I surf to another image, and again I save it as "000.jpg" and now it asks me if I want to replace the existing filename, although the existing one is "000" and I try to save as "000.jpg", so I say yes, and then magically the file is saved with the full filename including the extension "000.jpg"
    When I did it a couple of times, always saving image as "000.jpg" from various sources, I ended up with two distinct files named "000" and both in the same folder Pictures.
    Please advise.
    it sounds to me like you saved one file as 000.jpg and the other and 000.jpg.jpg.
    check the info panels for the files for full names to verify if this is the case.

  • Load external file as a blob?

    Hi!
    The target is: to check TGA file's color depth.
    How? - to load file as a blob and to read byte number 16.
    Similar to get information about compression etc...
    So, the question is - is it possible to read an external file by javascript in AE?
    Thank you in advance!

    Pg. 47 of the JavaScript Tools Guide CC.pdf talks about the File object. My guess is that you may need something more than just ExtendScript to dive that far into a file as I didn't see any obvious direct answer in the guide.

  • Differences between lrcat and lrdb files with new OS and LR 2?

    So I just refurbished my machine by wipping my drives that contain the
    operating system (Win XP Pro) and other program files. I did regular backups
    of all including the various settings for lightroom and everything else I
    could find outside of the backup that LR would do on it's own. Previously,
    before this refurbishment, I was using LR 1.4 and just did install LR 2.1. I
    hadn't upgraded any of my LR databases as I created a temporary picture
    database on another drive just to test drive 2.1. So essentially, I had both
    LR 1.4 and LR 2.1 install simutaniously. Didn't have any issues either, but
    again, just checking out 2.1 prior to abandoning 1.4. Anyhow, in my new
    setup I was just going to go with LR 2.1. Realizing that my catalog files
    (.lrcat) would prompt to be updated, I am thinking I am fine. But since
    Adobe's LR likes to place files all over the place from 'program files' to
    'application data' to 'my pictures', I ended up with what "seems" to be some
    duplicates and/or am a bit confused as I am not sure what goes where. I
    mean, I think I have it all down as I backed up some items such as the lrdb
    files and then brought in some stuff I had backed up before this
    refurbishment. All seems fine, but I would rather aviod issues in the
    future. So could someone tell me what goes where and their file name(s) and
    extensions? And when doing this, what is the difference between the lrcat
    and the lrdb files? Seems LR 2.1 doesn't contain or create lrdb files. And
    lastly, where are my preview files? When I set the lrcat files to point to
    my old setup/stuff, the pictures just take a very quick moment before they
    are clear and whatnot. Is it best just to recreate? And lastly, is there a
    way for me to test and check to make sure I moved the right things into the
    right places and that all is working as it should with the proper files? As
    an example, all the folders/files that were here "C:\Documents and
    Settings\Mark G\Application Data\Adobe\Lightroom" I just copied and wrote
    over from my backup prior to the refurbishment and things such as my custom
    and downloaded web galleries look fine. Any other thoughts? Sorry for the
    long read and thanks for any and all help/input you all can provide.

    >And when doing this, what is the difference between the lrcat
    >and the lrdb files?
    In versions up to and including V1.0, Lightroom catalog files were .lrdb (for Lightroom database). So, if you have already been working with V1.4 you can get rid of any .lrdb files that you may still have.
    As regards file locations you could do searches for the following file types:
    .lrcat (catalogues and backed-up catalogues)
    .lrtemplate (templates and presets)
    .agprefs (your preferences file)
    previews.ldata (in same folder and with same name as your catalogs)
    Lightroom allows you to choose where your catalogs (and associated previews) are stored. It also allows you to specify where Lightroom backs up your catalogs.
    Templates and presets are stored in C:\Documents and Settings\YourUsername\Application Data\Adobe\Lightroom
    This message gives you a summary of files and it references a Tech Note: http://www.adobeforums.com/webx/.3bc3994c

Maybe you are looking for