gpt4 book ai didi

php - 添加更多自定义变量到 mysql insert on blueimp/jquery-file-upload

转载 作者:行者123 更新时间:2023-11-29 03:35:26 25 4
gpt4 key购买 nike

我目前正在通过 mysql 在 blueimp/jquery-file-upload 脚本中插入标题和描述。我用了this教程让我到达那里,但是,我需要添加另一个变量。该变量是当前登录用户的 session ID $_SESSION["userid"] ,我想将它插入到我添加的名为 uid 的列中.通常很容易将另一列插入到插入中,但是这个脚本非常敏感,每当我弄乱它时,即使是最轻微的一点,我都会得到“SyntaxError: Unexpected token <”。任何帮助将不胜感激。

/server/php/index.php

$options = array(
'delete_type' => 'POST',
'db_host' => 'localhost',
'db_user' => 'fpform_fanuser',
'db_pass' => '*****',
'db_name' => 'fpform_fandata',
'db_table' => 'files'
);

error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');

class CustomUploadHandler extends UploadHandler {

protected function initialize() {
$this->db = new mysqli(
$this->options['db_host'],
$this->options['db_user'],
$this->options['db_pass'],
$this->options['db_name']
);
parent::initialize();
$this->db->close();
}

protected function handle_form_data($file, $index) {
$file->title = @$_REQUEST['title'][$index];
$file->description = @$_REQUEST['description'][$index];
}

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

protected function set_additional_file_properties($file) {
parent::set_additional_file_properties($file);
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$sql = 'SELECT `id`, `type`, `title`, `description` FROM `'
.$this->options['db_table'].'` WHERE `name`=?';
$query = $this->db->prepare($sql);
$query->bind_param('s', $file->name);
$query->execute();
$query->bind_result(
$id,
$type,
$title,
$description
);
while ($query->fetch()) {
$file->id = $id;
$file->type = $type;
$file->title = $title;
$file->description = $description;
}
}
}

public function delete($print_response = true) {
$response = parent::delete(false);
foreach ($response as $name => $deleted) {
if ($deleted) {
$sql = 'DELETE FROM `'
.$this->options['db_table'].'` WHERE `name`=?';
$query = $this->db->prepare($sql);
$query->bind_param('s', $name);
$query->execute();
}
}
return $this->generate_response($response, $print_response);
}

}


$upload_handler = new CustomUploadHandler($options);

最佳答案

假设您想要更改您的 INSERT 查询(您发布的代码中只有一个 INSERT 查询),这就是您需要更改的内容:

if (empty($file->error)) {
$sql = 'INSERT INTO `'.$this->options['db_table']
.'` (`name`, `size`, `type`, `title`, `description`, `uid`)'
.' VALUES (?, ?, ?, ?, ?, ?)';
$query = $this->db->prepare($sql);
$query->bind_param(
'sisss',
$file->name,
$file->size,
$file->type,
$file->title,
$file->description,
$_SESSION['userid']
);
$query->execute();
$file->id = $this->db->insert_id;
}

关于php - 添加更多自定义变量到 mysql insert on blueimp/jquery-file-upload,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22517699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com