2013-09-25 51 views
1

我创建了一个带有几个字段的表单,比如“标题”,“日期”,“textarea”和用PLupload上传照片的选项。创建一个带有多张照片上传(PLupload)的表单

但是,上传表单并将照片附加到我的数据库中的正确帖子的最佳方式是什么?

我现在的方法是,当点击保存按钮:

function save() { // javascript function 

    // step 1. do an empty jquery post, so I get a (database) ID of my new post 

    // step 2. start PLupload upload, with as parameter the ID from step 1 (using multipart_params in PLupload) 

    // step 3. when PLupload is ready, update the form with the complete content (title, date, textarea. 

} 

但是这种方法是一个简单的形式有点复杂。我正在寻找更简单的方法。我怎样才能做到这一点?

回答

0

这是我过去几次遇到过的问题(有几个ajax上传者)。

我想出的一个解决方案是生成一个包含日期和时间以及随机数的ID,然后在帖子表和照片表中插入此ID。所以posts表中会有一个额外的“files_id”列和照片表。

<?php 
$files_id = date('ymdhis').rand(0,9999999999); 
?> 

可能不是一个100%安全的解决方案,所以我会好奇,如果有任何其他的建议。