Forum Moderators: coopster
filename: image.php
<?php// CODE FOR ACCEPTING GET VARIABLES IF SERVER DOESN'T SUPPORT IT AUTOMATICLY
if (ini_get('register_globals')!= 1) {
$supers = array('_REQUEST','_ENV','_SERVER','_COOKIE','_GET','_POST');
foreach ($supers as $__s) {
if (is_array($$__s) == true) extract($$__s, EXTR_OVERWRITE);
}
unset($supers);
}
$link = mysql_connect("localhost", "vs022_celebx", "****xx")
or die("Can't connect.");
mysql_select_db("vs022_celebx")
or die("Can't select database.");
if (!$id) { print "ERROR NO ID"; } else {
$result = mysql_query("SELECT * FROM se_keys where id='$id' LIMIT 1");
while($row = mysql_fetch_array($result)) {
if ($row[image]) {
header("Content-Type: $row[image_type]");
print "$row[image]";
}
}
}
?>
but the result is an continious loading file and no imagedata shown.
Please help!
Best Regards,
Snt
As a side note - It's usually better to store a pointer to the image instead of the actual image itself in the database. Depending on the size of the database and how you have your indexes set up it may just be taking a long time to find what your looking for and your code might be OK and you wouldn't know it.
JAG
mysql_select_db ("arrowhea_homes");
$result = mysql(arrowhea_homes, "select * from homes"); //results
$homes = mysql_numrows($result);
$i = 0;
while($i < $homes) {
echo "<TR>";
echo "<TD>";
echo mysql_result($result,$i,"MLS");
echo "</TD><TD>";
print mysql_result ($result,$i,"IMGSM1");
echo "</TD><TD>";
echo mysql_result($result,$i,"price");
echo "</TD>";
echo "</TR>";
$i++;}
?>
</TABLE>
</body>
--------------end -----------------------
kinda need my hand held here...
Yours cannot work because you are sending out the header command for an image and then html and then the image. If you send the header like you are doing then just send the image.
If you want to have a mix of html and images then the easiest thing to do is store a pointer to the image and where you have...
print mysql_result ($result,$i,"IMGSM1");
change it to an <img> tag where the $result is the location of the image. Then you can get rid of the header also.
JAG
I didn't get it to work yet, I've tried any possible setup but it still doesn't work, the imagedata call via PHP does work when building real image files with it bt when calling it via an header or as direct output from PHP it just keeps loading the file...
Let me know if you know a solution.
Best Regards,
Snt
[edited by: celebx at 1:30 pm (utc) on Jan. 29, 2004]
The output of the BLOB data does seem to work since I am able to build real files with it from within PHP so it must be an other problem...
Let me know if you have an idear.
Best Regards,
Snt
I manually assigned $id a character value of '1'.
I assigned the image_type a character value of 'image/jpeg'.
I uploaded a jpg image into the image blob.
I did get an error becuase if ($row[image]) had to be if ($row['image']) which caused the actual image not to show but once changed the image displayed just fine.
So assuming those variable are correct on your site then it should work. Double check to make sure.
JAG