0

Does anyone know how to save an image into my SQLite db with Doctrine2? I already got a BLOB "pic_data" and a string "pic_type", but how do i hava to go on?

Greetings, BigTeddy

jhbruhn
  • 868
  • 2
  • 10
  • 23
  • Do you really need to store the image in the DB? Can't you store it in the file system see http://stackoverflow.com/a/3751/1059001. – P. Galbraith Mar 04 '12 at 12:53
  • Well okay I'll do it like this... :D But how should the files be named? – jhbruhn Mar 04 '12 at 12:54
  • It doesn't matter what the files are called if you store the file name in the database instead of the file itself. – P. Galbraith Mar 04 '12 at 12:58
  • But if two people upload a picture with the same name? E.g. A uploads picture "cake.jpg" and B uploads another picture named "cake.jpg". – jhbruhn Mar 04 '12 at 12:59
  • Do you need to retain the filename or can you just append the system timestamp (see php time() function) to the filename? Like cake_1138618081.jpg. – P. Galbraith Mar 04 '12 at 13:27

1 Answers1

1

Do you really need to store the image in the DB? Can't you store it in the file system.

See Storing Images in DB - Yea or Nay? for discussion about this.

You can just append the system timestamp (see php time() function) to the filename to make it unique.

$newFilename = time().'_'.$filename;

//results in 1138618081_cake.jpg
Community
  • 1
  • 1
P. Galbraith
  • 2,477
  • 21
  • 24