Re: [Phplib-users] Classes, MySQL, Images & phplib
Brought to you by:
nhruby,
richardarcher
From: Mike G. <mi...@op...> - 2001-12-31 17:34:46
|
Hi Nathan, 1st - Damn your a good resource.. nathan r. hruby wrote: > 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']; > } > } > } OK.. My present code looks like this: require('config.php3'); class Image { var $db; function Image($ID='$GLOBALS[ID]') { $this->db = new DB_Sql; $sql="SELECT photo FROM WLPphoto WHERE profileID='$ID'"; $this->db->query($sql); while ($this->db->next_record()) { Header("Content-type: image/jpeg"); print $this->db->Record['photo']; } } } and produces only this: <html><body></body></html> I just want to clarify though.. in the example you gave ($this->db = new nameOfdbClass;), if I was trying to add this to phpSlash 6.2 nameOfdbClass; would be DB_Sql (or would it be slashDB? Both seem to produce the same result for me.. I even tried commenting out the header line (Header("Content-type: image/jpeg");) to see if that would just echo the raw jpg data.. It didn't.. So something's goofing up... > 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; > } > } This is useful code.. Likely better than the current upload script offers.. However, it is already using imagesize once to insert the data (not that you would know that), so there's no need to do it again afterwards.. Mike -- Mike Gifford, OpenConcept Consulting, http://www.openconcept.ca Supporting progressive organizations in online campaigns and tools. Feature: Women's Learning Partnership http://learningpartnership.org Truth is that which confirms what we already believe. Northrop Frye |