sputnik577 Posted September 18, 2006 Share Posted September 18, 2006 How can i load a picture from a mySQL database using php. The picture is uploaded in a table and then dynamically loaded to a php page. It's attribute in the database table is longblob.[code]while(list($name, $type, $size, $path) = mysql_fetch_array($imgResult)) { $im = open_image($path);if ($im === false) { die ('Unable to open image');}header ('Content-Type: image/jpeg');imagejpeg($path);echo 'Opened image';function open_image($path) { # JPEG: $im = @imagecreatefromjpeg($path); if ($im !== false) { return $im; } # GIF: $im = @imagecreatefromgif($path); if ($im !== false) { return $im; } # PNG: $im = @imagecreatefrompng($path); if ($im !== false) { return $im; } # GD File: $im = @imagecreatefromgd($path); if ($im !== false) { return $im; } # GD2 File: $im = @imagecreatefromgd2($path); if ($im !== false) { return $im; } # WBMP: $im = @imagecreatefromwbmp($path); if ($im !== false) { return $im; } # XBM: $im = @imagecreatefromxbm($path); if ($im !== false) { return $im; } # XPM: $im = @imagecreatefromxpm($path); if ($im !== false) { return $im; } # Try and load from string: $im = @imagecreatefromstring(file_get_contents($path)); if ($im !== false) { return $im; } return false;}[/code] Quote Link to comment Share on other sites More sharing options...
Balu Posted September 18, 2006 Share Posted September 18, 2006 Hi, I am new in PHP, so I don't realy understand what you mean with that script, but when I uploading some images (by FTP functions), i put to MySQL DB only path, where the required picture is located. I also store an orgiginal filename (wallpaper3.jpg) , actual filename (file0018.jpg) which shold be generated by PHP and ID. Than just load info from DB and use <IMG SRC="..."> ;) Quote Link to comment Share on other sites More sharing options...
ci5ic Posted September 18, 2006 Share Posted September 18, 2006 I agree...What I do is write a script that uploads the image to a specific directory, renaming it using php's date() function. Then, I insert into a database the new name of the uploaded image, as well as any other data I want to associate with the image (comments, who uploaded the image, the upload date, file size, etc.).Then, when I want to display the image, I run a MySQL query for the information, and use the image name in the database to display the image, like such:$imagefile = mysql_result($result,$i,"imagefile");print "<IMG SRC='../images/$imagefile'>";very simple.... Quote Link to comment Share on other sites More sharing options...
sputnik577 Posted September 18, 2006 Author Share Posted September 18, 2006 i've tried that, i've made the attribute a varchar and that would point to the file but the server said it could not find the image on the server. Quote Link to comment Share on other sites More sharing options...
sputnik577 Posted September 18, 2006 Author Share Posted September 18, 2006 so now i've changed the attribute to mediumblob and i'm not getting anything.I don't know what else to do.Greg Quote Link to comment Share on other sites More sharing options...
sputnik577 Posted September 18, 2006 Author Share Posted September 18, 2006 anybody anything, take a look at my code and see if you can see any mistakes Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.