![]() |
passing binary (or long) data (dynamic images)
Let's suppose I capture a bunch of raw data to a variable.
For example: :
//page.phpor :
//page.phpOkay, so let's suppose I've got $photo (a huge long string of data) and I've got $photo_type (the mime type for whatever type of image it is). Now I could display this as an image by doing: :
//page.phpThat's all fine and good but I don't want page.php to be the image itself. I want it to have the image in it as an <img> tag like: :
//page.phpI've made the following workaround: :
//page.phpDo I actually have to pass the data? The reason for the HTML code <img src=url> is simply to make an http request and recieve the response. Is there any way I can use PHP to bypass the request entirely and give the response (which would be "Content-Type: $type\n\n$photo") directly? Any help appreciated, wooz |
Are you wanting to do this with two files then, or just one?
If you want to keep within the same file, you can do something like this: :
<?phpOtherwise, with two files, it would probably be easier just to query in the image file itself according to whatever parameters you put for GET. When you put an image tag, it's already been processed independent of your script save for whatever you send through GET or whatever you have saved somewhere (file, database, session, cookie). |
That code doesn't actually work. If there is the $image variable (I'm not dealing with existing image files BTW) then the code renders the page itself as an image file. The "else" clause makes a html tag that feeds a file name to a php page.
|
The $image variable within the condition was an example used for testing. You would replace that with however you get your image content (temporary file while uploading or from database).
If the GET parameter is set, yes, it will render itself as an image. It defaults to the else first so it displays the img tag, which requests itself along with a GET parameter based on your filename. (You would take out file_exists and put maybe !empty since it doesn't exist permanently.) This was just to show one possible solution of how you could do it, which works in itself. You would need to modify it a little, probably passing whether it was from a temporarily uploaded file ($_FILES) or the database. (Except with $_FILES, if you didnt want it permanent, I would probably either temporarily put it somewhere and get the info or put it into the database first and then get the info.) |
I tried it but if I put a header request in a page it overrites the entire page as just the image.
That is: :
<html><html> <h1>Hi there</h1> <?php {image} Now how was that. </html> [/code] as I'd like it too. The header() starts a whole new page so all I get is the image as an image file. <img src="file"> is "shorthand" (sorta, though not really) for "Make a request indicated by the name and put the returned content here". My problem is I have no source name and I already now the content right here. So far as I know there is no way to manipulate HTML to give the content tag the content directly. We can't to <img content="@jfkui$_$mpv...bunch of binary code kilobytes in length"> nor can we use PHP to do something like <img src="<? temp_file(header('content'), content($image))?>"> where temp_file() is some place holder for a non-existant file whose content is "$image". I tried doing: :
first_page.php::I'm thinking I could do it by POST but am not sure how to call it. What I'm hoping I can do is something like: :
echo "<h1>Hi there</h1>"<img> is an http request. The browser fills in with the content of the response. Is there PHP code that can allow me skip the request but request that a response of my programming (it would be "Content-type: $type\n\n$image") be filled in? |
In reference to my example, why don't you put your page within the else {} block? In the script, they are acting as two, completely different pages, not like one page within another. That's why both are separated in the first place: the image content has to be all by itself with just its headers to care for it =P
|
Quote:
Level0)At the browser level what I want the user to see is web page that looks something like this: ::::::::::::::::: HI THERE http://www.sirentiger.com/fatherbear.jpg ::::::::::::::::: Level1)At the HTML code level that be something like: :
<h1>HI THERE</h1>Now, the page itself (lets call the page itself "page.php") is a http request/response and the <img> is a second http request/response which I say is "within" the page although that could be rather lazy semantics. (Quite probably, I am badly abusing technical and precise terminology do to a less than thourough understanding http-request/response mechanics. If so, I apologize and I hope to be enlightened.) Level2) at PHP code I want to one of two things (although maybe neither of these things are possible). Either I want to write a a second sepearate PHP script (Let's call the second script "image.php") which renders the image: a-- :
page.php::::
page.php:
page.php:
page.php |
A temp solution
Okay, this works (mostly)
:
<h1>HI THERE</h1>I don't know how to put off calling unlink untill after the page has loaded. Anyone know? Still this is a *huge* improvement! |
I perfectly understand what you are trying to do.
What I mean is, the if/else block acts as two completely different pages. You cannot mix the two by putting browser output (HTML, etc) outside of the if/else block The solution you posted works, except can make the file server messy with a bunch of temporary files. (You can put unlink at the bottom of your script. HTML will load it properly, then unlink will delete it and, since it's already loaded, it wont affect the page display. Just if they try to save it or go to it, it wont exist.) So, this is a revamped example. This instead takes image data from a database (based on my table at the bottom): :
<?phpDo you understand what this does? Edit: Here's an example. |
Okay, I finally see what you are saying. I'll give it a try but I think it might be complicated (if not impossible) to redo all the programming that I did to get the image. In fact if I get the image from a POST FILE field I think its an IE browser security feature that it can't be be resent.
|
| All times are GMT -5. The time now is 9:50 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC