Re: [Phplib-users] Classes, MySQL, Images & phplib
Brought to you by:
nhruby,
richardarcher
|
From: nathan r. h. <na...@ds...> - 2001-12-31 16:35:28
|
On Mon, 31 Dec 2001, Mike Gifford wrote:
> Hello,
>
> I'm having a bit of trouble convincing a phplib class to produce an
> image from a MySQL database..
>
> So far I've got the following:
>
> require("config.php3");
> class Image {
> var $db;
> function Image() {
> global $ID;
> $img->db = new Image;
> $sql="SELECT photo FROM WLPphoto WHERE profileID='$ID'";
> $img->db->query($sql);
> while($img->db->next_record()) {
> Header("Content-type: image/jpeg");
> echo $this->db->Record[photo];
> }
> }
> }
>
require('config.php');
class Image {
var $db;
// Suck in the ID from the GLOBALS array, handy becasue you can chnage
// the ID at runtime if'n ya want.
function Image($id = $GLOBALS[ID]) {
// Above you instance the wrong class (the one you're running,
// suprising this should have caused an infinate loop)
// The reason this wasn't working is beacus you never instanced the
// phplib class
$this->db = new nameOfdbClass;
$sql = "blah blah blah"
$this->db->query($sql);
while ($this->db->next_record()) {
header("here's an image");
print $this->db->Record['photo'];
}
}
}
Note that you can ahould be able to run run imageSize() on the sql
refernce adn double check it's image type before sending the header.
Here's chuck of code I have for one project, you'll need to modify it for
your own purposes, but it's an ok example of imagesize()
function getType() {
if ($debug) {
echo "Getting Type";
echo "image::getType() - type is $this->currImg['imagesize'][2]<br>\n";
}
switch ($this->currImg['imageSize'][2]) {
case 1:
return("gif");
break;
case 2:
return("jpeg");
break;
case 3:
return("png");
break;
case 4:
return("swf");
break;
default:
return("unknown");
break;
}
}
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
nathan hruby / digital statement
na...@ds...
http://www.dstatement.com/
Public GPG key can be found at:
http://www.dstatement.com/nathan-gpg-key.txt
ED54 9A5E 132D BD01 9103 EEF3 E1B9 4738 EC90 801B
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|