bugzy Posted July 13, 2012 Share Posted July 13, 2012 Hello this is my very 1st time to insert a data with an image coordinated with it... I have like this tables and their columns Category Table category id(PK) category name Item Table item_id(PK) item_category(FK) item_name item_sale(bool) item_registered If I'm going to add an item with coordinated image, I don't know how will I put the image. is it everytime I'm going to add a category, is it supposed to generate a folder? for let's say category "laptop" so all items's images with a category laptop will be put on that folder laptop? in that case will category id will be the foreign key? I hope someone will teach or explain me the proper way to do this... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/265638-need-help-on-proper-approachinserting-data-with-img/ Share on other sites More sharing options...
scootstah Posted July 13, 2012 Share Posted July 13, 2012 You could create folders, but that might end up being a pain later on. What you might want instead, is to physically store the images in the same place on the disk, and then categorize them in the database. Quote Link to comment https://forums.phpfreaks.com/topic/265638-need-help-on-proper-approachinserting-data-with-img/#findComment-1361389 Share on other sites More sharing options...
Anonim250 Posted July 14, 2012 Share Posted July 14, 2012 Here is how I would do it (pseudo code): $imageFilename = sprintf('%s_%s.%s', $realImageName, $guid, $extension); SaveImage($tmpFileName, $imageFilename); // save to /images/myimage_GUID.jpg for example $sql = "INSERT INTO Item SET ..., item_image = {$db->Quote($imageFilename)}, ..."; $db->Execute($sql); Quote Link to comment https://forums.phpfreaks.com/topic/265638-need-help-on-proper-approachinserting-data-with-img/#findComment-1361442 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.