blueimp jQuery-File-Upload添加用户名

时间:2016-05-02 22:46:06

标签: php jquery angularjs ajax blueimp

我需要有人有经验(blueimp fileupload jquery)

https://github.com/blueimp/jQuery-File-Upload

它适合我的需要,但我需要添加用户会话与每个文件插入到mysql db我已经做了很多调查,但不幸的是,没有发现任何有用的。一般而言,基本创建如下:

protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
        $index = null, $content_range = null) {
    $file = parent::handle_file_upload(
        $uploaded_file, $name, $size, $type, $error, $index, $content_range
    );
    if (empty($file->error)) {
        $sql = 'INSERT INTO `'.$this->options['db_table']
            .'` (`name`, `size`, `type`, `title`, `description`)'
            .' VALUES (?, ?, ?, ?, ?)';
        $query = $this->db->prepare($sql);

        $query->bind_param(
            'sisss',
            $file->name,
            $file->size,
            $file->type,
            $file->title,
            $file->description
        );
        $query->execute();
        $file->id = $this->db->insert_id;
    }
    return $file;
}

我怎么能这样做? 提前谢谢!

1 个答案:

答案 0 :(得分:0)

您可以尝试以下操作:

protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
    $index = null, $content_range = null) {
$file = parent::handle_file_upload(
    $uploaded_file, $name, $size, $type, $error, $index, $content_range
);
if (empty($file->error)) {
    $mySession = $_SESSION['foo'];
    $sql = 'INSERT INTO `'.$this->options['db_table']
        .'` (`name`, `size`, `type`, `title`, `description`, `session`)'
        .' VALUES (?, ?, ?, ?, ?, ?)';
    $query = $this->db->prepare($sql);

    $query->bind_param(
        'sissss',
        $file->name,
        $file->size,
        $file->type,
        $file->title,
        $file->description,
        $mySession
    );
    $query->execute();
    $file->id = $this->db->insert_id;
}
return $file;
}

$mySession存储您的Session参数。

$sql查询中添加了一个新的数据库字段。

bind_param已更新。

希望这有帮助!