PHP, MySQL, BLOBs and PDF...help needed

A

Anonymous

Guest
Hi
I have a MySQL DB table with the following structure:


Scans
----------------------------------------------------
| ID | Name | Source | Date | File |
|---------------------------------------------------
| 1 | PC 1 | Old | 10/03/04 | [BLOB] |
| 2 | PC 1 | New | 19/03/04 | [BLOB] |
| 3 | PC 2 | Old | 11/03/04 | [BLOB] |
| 4 | PC 2 | New | 21/03/04 | [BLOB] |
| 5 | PC 3 | New | 23/03/04 | [BLOB] |
----------------------------------------------------


What I need to do is create a query where I can select the name, source and type from a drop-down and when I submit to stream the appropriate pdf file stored in BLOB to the browser window. Or if that is not possible, open Acrobat Reader. However, if at all possible I do not want anyone to be able to save or print the BLOB file once it has opened. I have two problems with doing all of this:

1) Getting the select statement to work. How do I make a dropdown that can select by the name, date or type while only displaying valid info for the specific query? Example: If I select PC 2 in my dropdown I need it to allow me to select Old or New with the respective dates and upon submitting, showing me the right blob file.

2) Is it possible to stream the BLOB to my browser somehow? Or is it possible to prevent someone from saving and printing if it opens through their Acrobat Reader?

I know this must sound really newb, but I would appreciate some help on this.
 
ladyath said:
1) Getting the select statement to work. How do I make a dropdown that can select by the name, date or type while only displaying valid info for the specific query? Example: If I select PC 2 in my dropdown I need it to allow me to select Old or New with the respective dates and upon submitting, showing me the right blob file.

I can only assume that what you're after here is a form in which the contents of one select box changes depending on what the user picks in another select box. Unless you want to reload the page after the user picks from the first box, you're going to have to do this on the client side, i.e. with JavaScript. JS isn't my strong suit (I really ought to learn it properly one of these days), so I'll leave that up to you.

Once you have the actual form done, turning it into a query is trivial. Just use conditionals (if or switch) to assemble a query based on what the user entered.

2) Is it possible to stream the BLOB to my browser somehow? Or is it possible to prevent someone from saving and printing if it opens through their Acrobat Reader?

Yes and no. You can store the contents of a PDF in a database and send it to the browser as a PDF (though there's very little practical advantage of this over just storing the PDF as a file and keeping the filename in the database). Basically what you have to do is use header() to send the right headers to the browser so it knows it's about to recieve a PDF and not HTML, and then send the data (just echo). Here's a decent tutorial to get you started, but there are a number available. Try Google. (Hint: header("Content-type: application/pdf")).

Concerning the second half of your question, no, it's not possible, and I'll tell you why: When you read a PDF file in your browser, what actually happens is that the file is downloaded to your computer, then Acrobat Reader is started, and Acrobat opens the file and displays it. To Acrobat, there's no difference between a PDF file on a web site and one on your hard drive. Your idea of "streaming" the file really isn't feasable (just for clarity, even "streaming" media files can be easily saved to your computer if you have the right tools).
 
I can only assume that what you're after here is a form in which the contents of one select box changes depending on what the user picks in another select box. Unless you want to reload the page after the user picks from the first box, you're going to have to do this on the client side, i.e. with JavaScript. JS isn't my strong suit (I really ought to learn it properly one of these days), so I'll leave that up to you.

Yes, I'd like the boxes to change depending on what was selected, but I am not sure how to code that either. I was assuming one would use JScript and I can do the function bits, but what would the code be on the PHP side? Basically a select that tells it to combine the query with with what was selected in a previous dropdown. Some tutorial advice would be perfect as well. I am just not sure what to call this to google it. 8-O
 
Back
Top