首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >blueimp jQuery-File-Upload添加用户名

blueimp jQuery-File-Upload添加用户名
EN

Stack Overflow用户
提问于 2016-05-03 06:46:06
回答 1查看 84关注 0票数 0

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

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

它符合我的需要,但我需要在mysql数据库中添加每次插入文件时的用户会话。我做了大量的调查,但不幸的是,没有发现任何有用的东西。一般来说,基本的创建如下所示:

代码语言:javascript
复制
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;
}

我该怎么做呢?提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2016-08-02 15:52:19

您可以尝试以下操作:

代码语言:javascript
复制
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存储您的会话参数。

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

bind_param已更新。

希望这能有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36992805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档