简体   繁体   English

blueimp jQuery-File-Upload添加用户名

[英]blueimp jQuery-File-Upload add user name

I need someone has experience with (blueimp fileupload jquery) 我需要某人有经验(blueimp fileupload jquery)

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

it suits my needs but I need to add the user session with every file insert to mysql db I've done a good deal of investigation, but, unfortunately, found nothing useful. 它适合我的需要,但是我需要将每个文件插入的用户会话添加到mysql db中,我已经进行了大量调查,但是不幸的是,发现没有什么用处。 In general, and The basic creation looks like this: 一般而言,和基本创建如下所示:

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;
}

How i can do this pls ? 我该怎么办? Thanks in advance! 提前致谢!

You can try the following: 您可以尝试以下方法:

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 stores your Session parameter. $mySession存储您的Session参数。

A new database field has been added to the $sql query. 新数据库字段已添加到$sql查询中。

The bind_param has been updated. bind_param已更新。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM