Hi gang:

In a previous post (i.e., [PHP] Strange response to MySQL query) I was trying to save a BLOB as a file, namely using an "INTO DUMPFILE" query.

If you are the system admin, and have all the system permissions, then this is not a big problem. However, if you aren't, then getting MySQL to dump a file becomes very problematic with respect to getting the right permissions to accomplish the task.

So, I found a way around it. I am sure that others have thought of this before me, so I'm not claiming credit and I am sure that this solution is obvious to some -- but, it's just that I searched literally hundreds of posts and spent considerable time without finding an answer. The following is the result of my tinkering. So here goes:

First, on your site create a file called "my_image.png"

Second, give it 777 permissions.

Third, in your code after opening the dB, grab the image from MySQL:

   $dbQuery = "SELECT image";
   $dbQuery .= "FROM $your_table ";
   $dbQuery .= "WHERE image_Id = $pageNum";

   $result = mysql_query($dbQuery) or die("Error: ".mysql_error());

Forth, drop the image into a variable:

   $fileContent = @mysql_result($result, 0, "image");

Fifth, create an image from a string (a great function here):

   $original=imagecreatefromstring($fileContent);

Sixth, save the image.

   imagepng($original, "my_image.png");

And Bingo, the image is now the "my_image.png" file.

Any comments or suggestions are welcomed.

tedd

--
--------------------------------------------------------------------------------
http://sperling.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to