brotherhood of LAN

msg:1309637 | 10:50 pm on Feb 22, 2003 (gmt 0) |
Most seem to just store the path to the image, rather than try to store the image itself (im not sure if you can store images, but i guess if you can store binary in mysql you can store anything) storing all the images in one folder and saving the filename as the primary key would be the way id try it.
|
andreasfriedrich

msg:1309638 | 10:51 pm on Feb 22, 2003 (gmt 0) |
There is nothing special about inserting an image into a BLOB [mysql.com] column. You just fopen() [php.net] the file, fread() [php.net] the file, use mysql_escape_string() [php.net] to escape any funny characters and the INSERT [mysql.com] it into the db using your usual mysql_query() [php.net]. $fp = fopen("s:/title.gif", "rb"); $content = mysql_escape_string(fread($fp, filesize("s:/title.gif"))); $y = mysql_query("INSERT INTO table SET content='$content'");
|
| HTH Andreas
|
dhdweb

msg:1309639 | 11:54 pm on Feb 22, 2003 (gmt 0) |
Please forgive me, I have a long way to go to master php! | $fp = fopen("s:/title.gif", "rb"); |
| What is the "rb"? | $y = mysql_query("INSERT INTO table SET content='$content'"); |
| What is the var $y for?
|
andreasfriedrich

msg:1309640 | 12:04 am on Feb 23, 2003 (gmt 0) |
>>What is the "rb"? This is explained in the PHP [php.net] manual entry for fopen() [php.net]: r = read, b = binary. >>What is the var $y for? This is explained in the PHP [php.net] manual entry for mysql_query() [php.net]: mysql_query() [php.net] returns TRUE on success and FALSE on error. It is a good idea to always check for success of an operation. Please read the manual entries for the functions you are using. Iīm making this really easy by providing the links, so there is really no excuse not to spend a little time exploring on your own. This will help a lot and while it may take some time at first you will benefit from it in the long run. HTH Andreas
|
dhdweb

msg:1309641 | 12:15 am on Feb 23, 2003 (gmt 0) |
Many thanks andreasfriedrich! Yea yea, I know ..... RTFM :) I'm now making yet another trip to php.net for more reading! (sometimes I just don't get their function explanations until I see a code sample that make sense!) dhdweb
|
andreasfriedrich

msg:1309642 | 12:30 am on Feb 23, 2003 (gmt 0) |
>>sometimes I just don't get their function explanations >>until I see a code sample that make sense! Thatīs alright and perfectly understandable. And whenever you have a question do feel free to post here. Itīs just that r = read is not one of those instances where the PHP [php.net] manual is hard to understand ;). Andreas
|
dhdweb

msg:1309643 | 2:48 pm on Feb 23, 2003 (gmt 0) |
| Itīs just that r = read is not one of those instances where the PHP manual is hard to understand ;). |
| You got me on that one, I somehow scanned right over that! I hate it when you can't see something that is right in front of your face, maybe I need new glasses? :) Thanks again andreas! dhdweb
|
lorax

msg:1309644 | 4:50 pm on Feb 23, 2003 (gmt 0) |
FWIW I'm in favor of BOL's approach unless you absolutely need to use a BLOB field. I'm not aware of any advantage of using BLOB - no smarty pants remarks Andreas ;) - over a simple VARCHAR containing the path.
|
hakre

msg:1309645 | 4:58 pm on Feb 23, 2003 (gmt 0) |
like lorax said, there might be even a big disadvantage by using blobs: if your webserver uses cgi for your scripts, then there might be a cgi-limit. if every picture has to be displayed out of a script, then on a listing with 20 entries, you'll get 20 extra cgi spawns only for the pictures. this can heavily stress your webserver and the limit can be reached quite fast. then only broken images would be displayed. on the other hand, it's easier to delete an item, because it's in the db only, not in the filesystem, too.
|
andreasfriedrich

msg:1309646 | 5:52 pm on Feb 23, 2003 (gmt 0) |
>>I'm not aware of any advantage of using BLOB [...] >>over a simple VARCHAR containing the path. I did not try to advocate either ;). In fact I sometimes do neither, that is I do not store the binary data in a BLOB [mysql.com] nor do I store the path of the binary file in the db. What I do is name the file after the value of the PRIMARY KEY [mysql.com] of the db. Andreas
|
andreasfriedrich

msg:1309647 | 5:55 pm on Feb 23, 2003 (gmt 0) |
>>if your webserver uses cgi If your host provides just the PHP [php.net] binary instead of the module then Iīd switch hosts ;). Andreas
|
globay

msg:1309648 | 9:00 pm on Feb 23, 2003 (gmt 0) |
Wouldn't it be easier, if they just upload them, via a formular?
|
lorax

msg:1309649 | 2:04 pm on Feb 24, 2003 (gmt 0) |
>> What I do is name the file after the value of the PRIMARY KEY of the db. That's another nugget I hadn't thought of. Thanks. :)
|
dhdweb

msg:1309650 | 11:58 pm on Feb 24, 2003 (gmt 0) |
To be honest, I scrapped this idea in favor of creating a PHP form that creates a new directory and allows the user to upload 5 pictures at a time. (much easier) I should have thought of this in the first place since all I really wanted was an easy way for users to send me thier pics with out having to use e-mail or FTP. Talk about having a brain fart! :) Now, once they have created the new dir and uploaded the pics, I just FTP them down to my computer. Thanks again for the info for the db, I may need that someday. dhdweb
|
|