2009年1月1日星期四

Re: [fw-core] Image upload and database insert, correct way

Thanks. Great advice.
One question. Will the below code work with MYISAM?
 
-R

 
On 1/1/09, Alan Gabriel Bem <alan.bem@gmail.com> wrote:

Well there is numerous of ways to do that.

I did some reconnaissance and have some advices:
1. Name your stored images with some unique hash (not database primary key)
e.g. sha1(time() . $original_name. It will prevent auto download via
bot-programs and original name collisions.
2. Use transaction during all upload logic.
try {
   $database->beginTransaction();
   // upload logic: move uploaded files, hash generating etc
   // database logic: inserting image data to database
   $database->commit();
catch(UploadException $e) {
   // just rollback and maybe some logging
   $database->rollback();
} catch(DatabaseException) {
   $database->rollback();
   // delete uploaded file as well, since db failed.
}

As you can see in my example step order doesn't really matter. Of course you
can do that in procedural code without OOP (but I don't recommend that).
--
View this message in context: http://www.nabble.com/Image-upload-and-database-insert%2C-correct-way-tp21239704p21242660.html
Sent from the Zend Core mailing list archive at Nabble.com.


没有评论: