0

I would like to store images in my mySQL database using the CodeIgniter PHP framework. How do I write and read the image?

Thank you.

thedp
  • 8,350
  • 16
  • 53
  • 95
  • 1
    Learning is all good, just be careful not to shoot yourself in the foot with storing images directly in the database. You can learn from the mistakes of others. ;) – Rex Morgan May 05 '10 at 18:17
  • 1
    So I've been reading, and I guess I will go with simple image directory and storing the url as you suggested. Thank you. – thedp May 06 '10 at 07:50

2 Answers2

4

You will have to use the file uploading class of CI to upload the files and use the models to save them to the database, here are related resources:

File Uploading Class
Models

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
3

It's considered bad practice to store the actual image files directly in a database. Instead you can just store a path to the file in the database and store the file in a directory on the server.

AstaHost Forums

Best approach for storing uploaded image

CodeIgniter - Uploading an Image through a form, store the location of the image in database

Community
  • 1
  • 1
Rex Morgan
  • 2,979
  • 2
  • 21
  • 32