By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

multi image print

tolkienarda
100+
P: 316
Hi all

below is a function that works to print out one image and my attempt to duplicate it in such a way that i can print multiple images the echo statement is in a loop and i don't know what the header("...") stuff is for but it was in the function is stole this code from

[PHP]
if ($_REQUEST[gim] == 1) {
header("Content-type: image/jpeg"); //don't know what this does
print $bytes; // bytes has the imgdata from one image stored in it
exit ();
}

//and in the body of the page

<img src=?gim=1 width=144>
[/PHP]

and here is my attempt this is in a loop
[PHP]

echo '<img src=" 'header("Content-type: image/jpeg"); $row[imgdata];' " '>

[/PHP]

thanks for input

eric
Feb 16 '07 #1
Share this Question
Share on Google+
15 Replies


Motoma
Expert 2.5K+
P: 3,235
[PHP]

echo '<img src=" 'header("Content-type: image/jpeg"); $row[imgdata];' " '>

[/PHP]

thanks for input

eric
NOPE.

What the first script is doing, rather than returning text in the form of HTML, it is returning binary data in the form of a JPEG image.

That means when you view the php file, and save it, you are saving an Image, rather than a web page.

It is not possible to embed things the way you are trying to.
Feb 16 '07 #2

tolkienarda
100+
P: 316
ok do you know a good way to display images out of a mysql database. i have done next to nothing with file storage in databases. with the exception of the project i am working on now i have alwasys just done text.

eric
Feb 16 '07 #3

Motoma
Expert 2.5K+
P: 3,235
1. Make a PHP script that, when given an image ID via $_GET, displays an image from the database.

2. Make a PHP script that prints <img src=...> tags, each one referencing the PHP script above.
Feb 16 '07 #4

tolkienarda
100+
P: 316
ok i will make those and post the results

thanks much

eric
Feb 16 '07 #5

tolkienarda
100+
P: 316
ok so i am stupid but here is my question

when i call this new php page do i do it somthing like this

newpage(title);

with newpage being the new php page and title being the variable being sent via GET

eric
Feb 16 '07 #6

Motoma
Expert 2.5K+
P: 3,235
ok so i am stupid but here is my question

when i call this new php page do i do it somthing like this

newpage(title);

with newpage being the new php page and title being the variable being sent via GET

eric
No, you will create a page called showImage.php.
When passed an imageid, it will retrieve it from the database and show that picture.
You will then have your other php page output this:
[HTML]
<img src="showImage.php?imageid=5" />
<img src="showImage.php?imageid=76" />
<img src="showImage.php?imageid=549" />
[/HTML]
Feb 17 '07 #7

tolkienarda
100+
P: 316
ok thanks sorry for the stupid questions

eric
Feb 18 '07 #8

Motoma
Expert 2.5K+
P: 3,235
No worries; everyone was a beginner once.
Feb 18 '07 #9

tolkienarda
100+
P: 316
i hopefully wont be a begginer for long i am going to a week training course in php and i hope that after that and some time applying the stuff they teach me i will be at least an ok programer.

eric
Feb 18 '07 #10

tolkienarda
100+
P: 316
ok i've tried everthing i can think of and it still won't work. below is the code and a link to the page.
http://www.steppinupwebdesign.com/cms/imgupload.php

the main part of this script is the imgprint() function it is near the bottom
[PHP]
if ($_REQUEST[completed] == 1) {
// Need to add - check for large upload. Otherwise the code
// will just duplicate old file ;-)
// ALSO - note that latest.img must be public write and in a
// live appliaction should be in another (safe!) directory.
move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");
$image = addslashes(fread(fopen ($_FILES['imagefile']['tmp_name'],'r'),filesize($_FILES['imagefile']['tmp_name'])));
if (strlen($instr) < 149000) {
mysql_query ("insert into pix (title, imgdata, location) values (\"".
$_REQUEST[whatsit].
"\", \"".
$image.
"\")");
} else {
$errmsg = "Too large!";
}
}

imgprint();//calls the image printer after images are uploaded



// If this is the image request, send out the image
/*
if ($_REQUEST[gim] == 1) {
header("Content-type: image/jpeg");
print $bytes;
exit ();
}
*/
?>

<html><head>
<title>Upload image</title>
<body bgcolor=white><h2>latest picture</h2>
<font color=red><?= $errmsg ?></font>
<center><img src=?gim=1 width=144><br>
<table>
<tr>
<td>
<?
function imgprint()
{
$result = mysql_query("SELECT * FROM pix");//this table has an four coloms; title(unique), imgdata, id, location
$rowcount = mysql_num_rows($result);
$i = 1;
while ($i < $rowcount)
{
$row = mysql_fetch_row($result);
$title = $row[title];
echo '<img src="imagedisp.php?title=$title" />';
$i++;
}
}
?>
</table>
<img src="imagedisp.php?title=asdf">
<b><?= $title ?></center>
<form enctype=multipart/form-data method=post>
<input type=hidden name=MAX_FILE_SIZE value=150000>
<input type=hidden name=completed value=1>
browse: <input type=file name=imagefile><br>
comments: <input name=whatsit><br>
then: <input type=submit></form><br>


</body>
</html>
[/PHP]

and here is imgdisp.php

[PHP]

$title = $_GET[title];
$result = "SELECT imgdata, type FROM pix WHERE title='$title'";
$Show = mysql ( $hDB, $hSQL );
$rows = mysql_num_rows($hShow);

if($rows<1){
// no image matches this query
}
else{
// at least one image has this title
$getPhoto = mysql_fetch_object($Show);

// we need to determine the mime type
$Type = $getPhoto->type;

// and send the correct header to the browser
Header("Content-type: $Type");

// now send the image
$Body = $getPhoto->body;
echo $Body;
flush();
}
[/PHP]

thanks eric
Feb 19 '07 #11

Motoma
Expert 2.5K+
P: 3,235
ok i've tried everthing i can think of and it still won't work. below is the code and a link to the page.
http://www.steppinupwebdesign.com/cms/imgupload.php
I went to the site, but could not find imagedisp.php which was the src for the img tag.
Feb 20 '07 #12

tolkienarda
100+
P: 316
crap i am stupid

the imgdisp.php file is in a subfolder. ahahahahahah i hate being stupid, so frustrating when i do stuff like this it makes me want to kick myself but i am to fat and can't reach my head. oh well i will have to settle for hitting my head against the moniter.

eric
Feb 20 '07 #13

tolkienarda
100+
P: 316
hi i am troubleshooting this code one line at a time and i am curious as to what this does

[PHP]
$Show = mysql ( $hDB, $hSQL );
[/PHP]

it is just below my mysql query

eric
Feb 20 '07 #14

Motoma
Expert 2.5K+
P: 3,235
hi i am troubleshooting this code one line at a time and i am curious as to what this does

[PHP]
$Show = mysql ( $hDB, $hSQL );
[/PHP]

it is just below my mysql query

eric
This isn't your code?
Spit out $hDB, $hSQL, and $Show. What makes sense?
Check the definition of mysql()
Feb 20 '07 #15

tolkienarda
100+
P: 316
i have been stealing bits and pices and i just realized how stupid that is because i end up spending more time troubleshooting the problems than i would if i built it myself and understood what was happening. and i just found a good tutorial that will explain all of the syntax i need to fix this so i will read that before i continue.

thanks for you help i have learned alot i my conversations with you

eric
Feb 20 '07 #16

Post your reply

Sign in to post your reply or Sign up for a free account.