1

我正在创建一个包含几个字段的表单,例如“标题”、“日期”、“文本区域”以及使用 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.

}

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

4

1 回答 1

0

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

我想出的一种解决方案是生成一个包含日期和时间以及一个随机数的 id,然后将此 id 插入到帖子表和照片表中。因此,posts 表将有一个额外的“files_id”列,photos 表也是如此。

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

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

于 2013-11-25T01:01:43.213 回答