I've made PHP script to store articles in database and then retrieve them. However, I want to store images too. Each HTML page, should have for instance 3 images. What's the simpliest way to use them in mysql ? I've tried storing filename path in column, however if I want to add 2 or more images I have to have 2 or more columns then.
How have you done it on Sitepoint?
I also want to make it available for my authors to attach their own images to the article. How can that(uploading files) be done in PHP?
Thanks for your help
I haven't read them, but the title seems to fit your need.
Hope they help.
If it what you really want to do (storing binary file in MySQL), or else you should just store the url/link to the image in MySQL, it's much more efficient.
I have done it with multiple images and storing the imagesnames and paths to one field, basically I created a || delimited string of the image names and store that. and to view them you just explode("||", $fieldfromdb);
To get them into a nice array to work with then to delete images from you do the same but pop the image from the array implode it back togther then stick it back in the database, as for uploading the images you need the copy() function Check out the manual.
If you want to store image paths then I suggest creating a separate table (Not using a || deliminated string) which has an ID column (which refers to the article/page id) an image descriptor (e.g. titleimage) and a column for the image url as this would follow good database design principals.
Okay Okay so I don't always have the best ideas. But they work, Karl's is probably better.
I do exactly the same as Freddy, I use a '|' delimited list of image urls as a field in the appropriate table, This way you can have a variable number of images per page without redundant imag1,image2 fields etc.
If the site needs it, I also add the image descriptions in as well ,using a seperate delimiter.
Which is more efficient depends greatly on the individual project.
Sweet thanks for backing me up firepages
thanks everyone..you've been really helpful...
I'll probably make new table for my images..thanks again..
Don't get me wrong freddy, it's not a bad idea and it's how I used to do the same job as well.
Firepages, there will be no redundant image1, image2 etc. columns in any tables with my method as the table only has one field per row for an image url.