|brotherhood of LAN|
| 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.
| 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'");
| 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?
| 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.
| 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!)
| 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 ;).
| 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!
| 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.
| 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.
| 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.
| 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 ;).
| 9:00 pm on Feb 23, 2003 (gmt 0)|
Wouldn't it be easier, if they just upload them, via a formular?
| 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. :)
| 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.