CodeIgniter Forums
Newbie: Best methods for working with Multiple Images - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Newbie: Best methods for working with Multiple Images (/showthread.php?tid=9925)



Newbie: Best methods for working with Multiple Images - El Forum - 07-13-2008

[eluser]ywftdg[/eluser]
Sorry if this very newbie level, but I am trying to find the best way to approach working with say multiple images in CI. I am working on portfolio site for a client (architects), and I have id,title,body, and images value for the database table projects. In the past I would store the image paths(comma separated) in my table. Then in the front end explode the array and loop through to spit them out. I am wondering if anyone has any better solutions, thoughts on this. The portfolio projects could range from having 1 image to maybe 20 images, so its different from post to post.

Alternate idea I had: read a directory (for that post id) for the images? So store a directory path instead o the actual image paths?

Curious what solutions anyones come up with or think works the best...


Newbie: Best methods for working with Multiple Images - El Forum - 07-13-2008

[eluser]Référencement Google[/eluser]
[quote author="ywftdg" date="1215983625"]In the past I would store the image paths(comma separated) in my table. Then in the front end explode the array and loop through to spit them out.[/quote]

Two things I can say here:
- Nothing that what you have done in the past is impossible with CI
- It's not a good way to store your images paths into 1 field and explode it after, I'll try explain how you should do below

What you may do is an image table separate from your portfolio table.

Let's say:
image_id | portfolio_id (foreign key to your main porfolio table) | image_path

Doing so, you can have how much images you want for a given portfolio item, then just retrieve them using a Join query.


Newbie: Best methods for working with Multiple Images - El Forum - 07-13-2008

[eluser]indocoder[/eluser]
Too pixel's solution is easier for us to manage rather than reading file from directory... but you're the one who design your application,... its up to you.


Newbie: Best methods for working with Multiple Images - El Forum - 07-14-2008

[eluser]ywftdg[/eluser]
Too Pixel, so what your saying is make a separate table, which would contain al image entries, ok. So if they have 5 images, you would end up with 5 new rows in that table, with a relative id to match the say project id, yeah? Is this easy to accomplish, in the admin process, like if I use a multi-image uploader, this is easy to accomplish writing? Sorry, I'm pretty rough with these things, but somehow get by..


Newbie: Best methods for working with Multiple Images - El Forum - 07-14-2008

[eluser]Référencement Google[/eluser]
Sure very easy to do.
I advice that you try it and if you encounter difficulties post here either your DB schema and PHP code.


Newbie: Best methods for working with Multiple Images - El Forum - 07-14-2008

[eluser]ywftdg[/eluser]
Thanks for the advice Too Pixel, I will indeed get back to this post on how it works out, or if I get in a snag. Thanks for the kind help!


Newbie: Best methods for working with Multiple Images - El Forum - 07-15-2008

[eluser]indocoder[/eluser]
do some loops for each file that user has been upload, validate it, then if its ok, insert it to the database.