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

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

 



So single-user disclaimer would apply?

Obviously, if you have numerous people accessing your dB and doing inserts and updates, then all the lock-down stuff needs to be implemented.

But, my code is not for that, but rather for someone (a single programmer) who wants to pull an image from a BLOB and save it as a file.

Normally, a civilian wouldn't be doing that for if they wanted to see a file, your code would simply pull the image directly from the MySQL to the web page. No need to save as a file.

However, after given it some thought, I would imagine that one could get a unique generated string, create a file with that string, give the file the correct permissions, then pull the image from the dB and save, do image processing, and then reload the image into a web page, and delete the file without any conflict. I can envision lot's of users doing that simultaneously without problems. BUT, I haven't tried it yet!

tedd


On 2/16/06, tedd <tedd@xxxxxxxxxxxx> wrote:
 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/



--
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