CodeIgniter Forums
Database Scaffolding and Photos question? Kinda lost.... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Database Scaffolding and Photos question? Kinda lost.... (/thread-16705.html)



Database Scaffolding and Photos question? Kinda lost.... - El Forum - 03-14-2009

[eluser]generalsalt[/eluser]
I'm pretty new to CI and mysql and have a question.

I am attempting to make a small portfolio site for myself, complete with titles, description and photos.

I am using CocoaMysql in OS X to create my database, pretty much following the blog video tutorial on this site.

I'm using the scaffolding feature to add descriptions and titles to my MySQL database, and that all works great.

My question is what do you do when it is time to add photos? I guess MySQL doesn't 'add' photos themselves but just the URL locations? Is this right? Honestly, I haven't a clue what to do when comes to this.

Ultimately, I'd like to be able to have a browse/submit button to upload photos to a folder of my choosing and have it do whatever (??) to the database so it updates.

Can anyone educate me a little on what to do here?

Thanks!


Database Scaffolding and Photos question? Kinda lost.... - El Forum - 03-14-2009

[eluser]generalsalt[/eluser]
Also, where would you want to have your images (or images folder if there isn't already a place for them) at? In the Applications folder? Root?


Database Scaffolding and Photos question? Kinda lost.... - El Forum - 03-14-2009

[eluser]jedd[/eluser]
Howdi. You've stumbled upon one of the many potential holy wars - images in or out of the database.

The distinction is this. For inside, the files are stored as BLOB (binary lump of data) within MySQL. These are effectively very very wide columns. For outside, the files are stored in your file system, and you store the path in the database.

From what you've described you want to keep your files outside of the database. So to answer your last question - it depends on whether you currently store them on your computer at all. If you do, then you probably don't want to duplicate that - so you should just refer to them wherever they are now. This may involve some permissions twiddling with your web server, but that's not a big problem.

If you want to keep them in your CI structure, then probably an 'assets/photos/' sub-directory (where assets is a peer to system). Be careful, though, as photo collections get huge fast.

If you're stuck on scaffolding, then you can still use that with this approach - you'll have a column called 'photopath' - say 256 characters long (not sure what OSX's or HFS's limits are). You can then type the path to your folder into that field.


Database Scaffolding and Photos question? Kinda lost.... - El Forum - 03-14-2009

[eluser]generalsalt[/eluser]
Thanks for the reply.

I think I would like keep the photos outside of the database, and refer to their location, from what you described it sounds cleaner.

I just want to clarify what you are saying: The way to do this is to upload the photos to a folder (which is a sibling of system), and add the photos' URL location (by hand) to a say, a row called "photo_url" (or something similar)?

I was hoping there was some kind of scaffolding type feature that would allow me to upload photos and have it save the location to MySQL, rather than adding each location by hand.

Is there a preffered way in CI to grab photos from the database and show them?


Database Scaffolding and Photos question? Kinda lost.... - El Forum - 03-14-2009

[eluser]jedd[/eluser]
Quote:I just want to clarify what you are saying: The way to do this is to upload the photos to a folder (which is a sibling of system), and add the photos' URL location (by hand) to a say, a row called "photo_url" (or something similar)?

That's a way, yes Smile photo_url or photo_path - or something meaningful like that, yes. I'd probably avoid using 'url' unless it really is one. It doesn't sound like it is.

You'd probably want to put some .htaccess style protection around the photo directory, of course, so it can't be accessed directly. Or putting it outside the web document root entirely is another option.

Quote:I was hoping there was some kind of scaffolding type feature that would allow me to upload photos and have it save the location to MySQL, rather than adding each location by hand.

Well, you could just write the code that you're talking about - that will let you upload the file, and record it in the database as it goes. Uploading is painful, though, compared to just copying the files across into that directory.

You could also just rattle up some PHP that did a scan of the directory, and inserted details of the existing files into the database.

Quote:Is there a preffered way in CI to grab photos from the database and show them?
[/quote]

Hmmm .. not quite sure what you mean. You'd probably pass the path_info (from the db) via the controller, to your view, as part of your view data, and then in the view just do the usual img src thing - is this what you mean?