• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Uploading to a database?

#1
[eluser]Andreia M.[/eluser]
Hello,

I'm new to both CodeIgniter and PHP, but not to programming (though I'm fairly noobish to that, too). I was wondering this:

I have a registration form that inserts some data into a database (ID, name, the usual). I'd like to enable the users to also submit an image (of a specified max size and width/height), which would be inserted in the database as well, one for each entry. The question is: what do I use to do that? The File Upload class (which, as I understand, uploads a file to a folder, not a database) or the Database class? A combination of both? Is there a way to do this?

Thanks in advance!

#2
[eluser]Dam1an[/eluser]
There are some recent threads about uploading images to the database so have a search for them

I personally prefer not to store images in a database, as it adds extra load on the DB, so I prefer having images/avatars/user_id.jpg although it's up to you

#3
[eluser]Andreia M.[/eluser]
[quote author="Dam1an" date="1244062630"]There are some recent threads about uploading images to the database so have a search for them

I personally prefer not to store images in a database, as it adds extra load on the DB, so I prefer having images/avatars/user_id.jpg although it's up to you[/quote]
Ah yes, silly me - should've searched first.
Good point on the DB load, though... mm.

#4
[eluser]Dam1an[/eluser]
The db load might not be an issue for you, depends how much traffic you get
Also, you mentioned the images will have amax size, so it shouldn't add too much, although I still think reading from disk will be easier Smile

#5
[eluser]Andreia M.[/eluser]
This site I'm doing is more of an experiment, truthfully, so it doesn't have a whole load of traffic - it's my sandbox of sorts Wink I'm using it mostly to learn PHP/CodeIgniter and other Web technologies... thanks for the tip, though. I hadn't considered that.

#6
[eluser]Dregond Rahl[/eluser]
storing some of the information in a database is useful, but read from the disk is better rather than saving the image in the database itself.

#7
[eluser]Jondolar[/eluser]
One benefit of storing to the database is you don't have to make your images directory writable which can help protect from hacking attempts. This could be especially beneficial if your software runs on shared hosting servers.

I'm not necessarily recommending storing the images in a database, just pointing out one benefit.

#8
[eluser]Dam1an[/eluser]
Jondolar, you could store the images out of the web root, so the only way to write to it is if you're an authenticated user via the script, which will only allow jpegs

#9
[eluser]Yorick Peterse[/eluser]
It's a good practise to not store physical data into the database. "Text" goes into the database, all the other stuff goes into a folder.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.