Solved

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

Posted on 2004-04-15
17
557 Views
Last Modified: 2013-12-12
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
Comment
Question by:ASG-
  • 8
  • 6
  • 2
17 Comments
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10840606
$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
 

Author Comment

by:ASG-
ID: 10842259
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
 

Author Comment

by:ASG-
ID: 10843121
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
 

Author Comment

by:ASG-
ID: 10843237
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
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10843297
no idea, maybe you can lower the points?
0
 

Author Comment

by:ASG-
ID: 10843437
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
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10843487
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
 
LVL 3

Expert Comment

by:WysG
ID: 10845233
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Expert Comment

by:WysG
ID: 10845248
> 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
 

Author Comment

by:ASG-
ID: 10845452
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
 

Author Comment

by:ASG-
ID: 10869150
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
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10869256
if its too much hassle it does not matter.
0
 

Author Comment

by:ASG-
ID: 10869597
hey jkna_gunn, why don't you copy my post and submit it here, then I'll accept it :)...
0
 
LVL 6

Accepted Solution

by:
jkna_gunn earned 250 total points
ID: 10869681
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
 

Author Comment

by:ASG-
ID: 10869721
It worked! thanks! You're the best!
0
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10869782
no worries, glad thats all sorted out
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now