Re: Saving a BLOB image to a file (SOLVED)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Gerry wrote:

What if several users try to access a different picture at the same
time? Won't that render the wrong image for some?

Gerry


Gerry:

Normally, it's not needed for civilians. This is for when YOU want to do some image stuff on your images, like to do some background processing via your code.

As for users, they just want to see the image and you can pull that out of your dB or files, whichever you prefer.

tedd

---



On 2/16/06, tedd <tedd@xxxxxxxxxxxx> wrote:
 Hi gang:

 In a previous post (i.e.,  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




--
Gerry
http://portal.danen.org/


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

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux