Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Mar 15th, 2007, 4:36 PM   #1
woozy
Newbie
 
Join Date: Mar 2007
Posts: 15
Rep Power: 0 woozy is on a distinguished road
Question passing binary (or long) data (dynamic images)

Let's suppose I capture a bunch of raw data to a variable.

For example:
//page.php
   $photo = fread(fopen($_FILES[$str]['tmp_name'], "r"), $_FILES[$str]['size']);
   $photo_type = $_FILES[$str]['type'];
captures the binary data for a file submitted by a form.

or
//page.php
$query = "SELECT photo FROM messages WHERE id = $id";
$conn = connect();
$result = $conn->query($query);
while ($row = $result->fetchRow()){$image = $row[0];}
will collect data of 'photo' is a "BLOB" field in a $sql database.

Okay, 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.php
   $photo = fread(fopen($_FILES[$str]['tmp_name'], "r"), $_FILES[$str]['size']);
   $photo_type = $_FILES[$str]['type'];


header('Content-Type: $photo_type);
$photo;

That'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.php
   $photo = fread(fopen($_FILES[$str]['tmp_name'], "r"), $_FILES[$str]['size']);
   $photo_type = $_FILES[$str]['type'];

?>
Hello <?= $name ?><br>
<img src="<? some code to render image ?>
My question is, how can I pass the $photo (and $photo_type) $variables to whatever "?some code to render image ?" is.

I've made the following workaround:
//page.php
   $photo = fread(fopen($_FILES[$str]['tmp_name'], "r"), $_FILES[$str]['size']);
   $photo_type = $_FILES[$str]['type'];

  $_SESSION['binary'] = $photo;
  $_SESSION['type'] = $type;
?>
Hello <?= $name ?><br>
<img src="image.php">

//image.php
get_session();
header("Content-Type: $_SESSION['type']");
$_SESSION['binary'];
but I'd prefer to pass the data directly. (Can I send them with POST if it's not a form response?)

Do 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
woozy is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
GOTO Sys. Tray Src. (code Snippet) Cipher Show Off Your Open Source Projects 1 Oct 17th, 2006 1:38 PM
Jackpot game zorin Visual Basic 3 Jun 10th, 2005 1:19 PM
Help in QBASIC (I think it's similar to VB) phoenix987 Visual Basic 3 May 9th, 2005 12:33 PM
Help with a QBASIC program phoenix987 Other Programming Languages 4 May 5th, 2005 12:27 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC