jQuery-File-Upload mysql select显示所有文件,而不仅仅是用户的文件

vik*_*iko 5 php mysql jquery jquery-file-upload

欢迎,

我有jQuery-File-Upload的问题.我将插件与MySQL集成 - > https://github.com/blueimp/jQuery-File-Upload/wiki/PHP-MySQL-database-integration当我将文件添加到数据库中时添加了记录:name file, id_user, active...这很好.

加载我的网站后,加载列表上传的文件:https://stackoverflow.com/a/15448692/2788495

我只想加载当前加载所有的用户文件.

jQuery代码:

    $.ajax({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: $('#fileupload').fileupload('option', 'url'),
    dataType: 'json',
    context: $('#fileupload')[0],
    formData:{
        user: '<?php echo $objSession->e_ident ?>'
    }
}).done(function (result) {
    $(this).fileupload('option', 'done')
        .call(this, null, {result: result});
});
Run Code Online (Sandbox Code Playgroud)

PHP:

protected function handle_form_data($file, $index) {
    $file->title = @$_REQUEST['title'][$index];
    $file->description = @$_REQUEST['description'][$index];
    $file->user=@$_REQUEST['user'];
}
    protected function set_additional_file_properties($file) {
    parent::set_additional_file_properties($file);
    if ($_SERVER['REQUEST_METHOD'] === 'GET') {
        $sql = 'SELECT `id`,`user_id` FROM `'
            .$this->options['db_table'].'` WHERE `name`=? and user_id=?';
        $query = $this->db->prepare($sql);
        $query->bind_param('ss', $file->name, $file->user);
        $query->execute();
        $query->bind_result(
            $id,
            $user
        );
        while ($query->fetch()) {
            $file->id = $id;
            $file->user=$user;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在JSON中,没有选项:"id"和"user".

Rog*_*sel 0

我不知道我是否理解正确你想要做什么。

我相信您想要显示其上传的文件的用户已通过会话登录到您的系统,是吗?

而这个“$objSession->e_ident”有用户id。

如果我是对的,你应该删除这个:

"user: '<?php echo $objSession->e_ident ?>'" 从ajax请求中,像用户id这样的东西应该只在服务器会话文件中,而不是在页面上。

您应该将用户 ID 直接放在查询绑定上,如下所示: $query->bind_param('ss', $file->name, $objSession->e_ident);

现在你的问题,你的查询看起来是正确的, $objSession->e_ident 真的给用户提供了正确的 id 吗?

进入数据库 user_id 列有哪些值?