• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 616
  • Last Modified:

Oracle and PHP BLOB, trying to load file from web page - open or save

Hey all,

I'm trying to perform a very common function here.  I have an oracle database that stores binary data for many types of files.  One field holds the binary data in a BLOB while another field holds the content type that is in the appropriate format to go into the Content-type header.  I had this working perfectly fine for a while and I made a few changes so it would work on a macintosh.  Now, when I try to load the file through a web page, I can download the file properly through IE on a Macintosh, but when I use IE or Netscape through windows I get an error.  Through IE, I'll click on a link to load file.php which passes an ID field that holds the ID of the desired database record.  I am loading file.php through the javascript window.open function.  So a new window will open and IE asks if I want to open/save/cancel "file.php?id=1005", in the past it has put the actual filename here as I have assigned it through the Content-Disposition header, but now it is giving me the actual name of the php file.  So I will click either save or open, and I get the following error :

"Internet Explorer cannot download file.php?id=1005 from 192.168.1.100.

Internet Explorer was not able to open this Internet site.  The requested site is either unavailable or cannot be found.  Please try again later"

The code for this is below file.php file is below.  Now if I remove the header() functions and simple print the contents of $results["BINARY_FILE"][0];, it will print the binary data out as text just fine.  I have verified that all the database fields are being retrieved.  
<?php

include("../includes/connection.php");
include("../includes/functions.php");


global $db_conn;

$cmdstr = "select * from uploads2 where upload_id=".$_REQUEST["id"];
$parsed = ociparse($db_conn, $cmdstr);

ociexecute($parsed);
ocifetchstatement($parsed, $results);

ob_start();

header("Content-Disposition: attachment; filename=".$results["FILENAME"][0]);
header("Content-type: ".$results["FILE_CONTENT_TYPE"][0]);

echo $results["BINARY_FILE"][0];

ob_end_flush();
?>

So... any ideas here?

Thanks,
  ASG-

0
ASG-
Asked:
ASG-
  • 8
  • 6
  • 2
1 Solution
 
jkna_gunnCommented:
$output_file = $results["FILENAME"][0];
$content_len = sizeof($results["BINARY_FILE"][0]);

header('Pragma: public');
header('Content-Transfer-Encoding: none');
header('Content-Type: application/octetstream; name="' . $output_file . '"');
header('Content-Disposition: inline; filename="' . $output_file . '"');
header("Content-length: $content_len");

taken from php.net

you prob need to change some stuff here
0
 
ASG-Author Commented:
jkna_gunn,
   I tried your suggestion and I still get the exact same thing.  I also tried altering the content-disposition to 'attachment'  and altering the content-type to read appropriately, but no luck there either.  I've also reverted back to old database files and php code to when it woked, now it is doing the same thing as well.  This is making me wonder if perhaps it is a php.ini setting that may have gotten altered.  I'll keep trying, any more suggestions would be appreciated.
0
 
ASG-Author Commented:
Okay, got it.. What helped me was someone's comment from php.net
----------------------------
I had problems getting IE 6 to open [or to 'save as'] a BLOB'ed Word-document even with all those nice examples below. This line saved my day: header("Cache-control: private");

<?
header("Expires: Mon, 26 Jul 2001 05:00:00 GMT");              // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");  // always modified
header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");                                    // HTTP/1.0
header("Cache-control: private");                          // <= it's magical!!
header("Content-type: ".$row['mime']);                          // 'application/msword' or 'application/octet-stream'
header("Content-Disposition: attachment; filename=".$row['orgname']);

echo $row['file'];
?>
--------------------------------

apparently the cache control is magical.. I'd like to  give jkna_gunn part of these points for getting me going in the right direction.  The info page for the header() function at php.net actually addresses this topic quite a bit.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ASG-Author Commented:
how do I go about accepting my own comment as the answer, I would basically like to split points.  I don't want to give anyone the impression that jkna_gunn's post was the complete answer..  but I don't see the split points options here.. I think it is because only one person has responded, so there are no others to split the points with.. but I need to know how to incorporate part of my comments as part of the answer...
0
 
jkna_gunnCommented:
no idea, maybe you can lower the points?
0
 
ASG-Author Commented:
okay.. now I do see the split points option simply because you posted again, then it gives me the option to split the points between your two posts.. Surely they have a way to handle a question that you answer yourself...

I might have to ask the service folk
0
 
jkna_gunnCommented:
dont know usually when people answer a question themselves they ask for a refund of the points. what you could do ask for a refund for this question, then create a new question with less points, then i will post on that and you can accept it
0
 
WysGCommented:
If you want you question close, post in Community Support http://www.experts-exchange.com/Community_Support/ 
Ask for the question to be deleted and to refund points to you
0
 
WysGCommented:
> I don't want to give anyone the impression that jkna_gunn's post was the complete answer..
Then again if jkna_gunn helped you with you problem you should accept his answer and give him a B or a C grade.
0
 
ASG-Author Commented:
Well, jkna_gunn's post simply reminded me that php.net was a good resource.  He didn't actually suggest anything that worked.  Honestly I'm fine with just giving him the full pointage but my concern is when others come to this topic, they'll go straight to the post that reads as Accepted Answer (this is what I usually do), and they'll get an answer that doesn't work.  For this reason it seems like rewarding the points to jkna_gunn's post would harm the effectiveness of experts-exchange... I'm surprised there isn't a better way to handle this.. I'll talk to community support or something..
0
 
ASG-Author Commented:
Basically I would like to give the points to jkna_gunn but want the green "Accepted Answer" next to the correct comment which was a comment made by myself.  Is there anyway for an Administrator to do this, and does experts-exchange have any intention of making this a function available to the author in the future?
0
 
jkna_gunnCommented:
if its too much hassle it does not matter.
0
 
ASG-Author Commented:
hey jkna_gunn, why don't you copy my post and submit it here, then I'll accept it :)...
0
 
jkna_gunnCommented:
I had problems getting IE 6 to open [or to 'save as'] a BLOB'ed Word-document even with all those nice examples below. This line saved my day: header("Cache-control: private");

<?
header("Expires: Mon, 26 Jul 2001 05:00:00 GMT");              // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");  // always modified
header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");                                    // HTTP/1.0
header("Cache-control: private");                          // <= it's magical!!
header("Content-type: ".$row['mime']);                          // 'application/msword' or 'application/octet-stream'
header("Content-Disposition: attachment; filename=".$row['orgname']);

echo $row['file'];
?>
--------------------------------
0
 
ASG-Author Commented:
It worked! thanks! You're the best!
0
 
jkna_gunnCommented:
no worries, glad thats all sorted out
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 8
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now