简体   繁体   中英

blueimp jQuery File Upload PHP MySQL database integration third textfield

I would like more than the two text fields 'title' and 'description' at upload, write to the DB. The DB is extended to the field 'datum'. The index.php - see below - file is expanded to include the new field. But it is written no entry. Also the upload form has been extended by the field 'datum'.

protected function handle_form_data($file, $index) {
    $file->title = @$_REQUEST['title'][$index];
    $file->datum = @$_REQUEST['datum'][$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`, `datum`, `description`)'
            .' VALUES (?, ?, ?, ?, ?, ?)';
        $query = $this->db->prepare($sql);
        $query->bind_param(
            'sisss',
            $file->name,
            $file->size,
            $file->type,
            $file->title,
            $file->datum,
            $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`, `datum`, `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,
            $datum,
            $description
        );
        while ($query->fetch()) {
            $file->id = $id;
            $file->type = $type;
            $file->title = $title;
            $file->datum = $datum;
            $file->description = $description;
        }
    }
}
$query->bind_param(
        'sisss',
        $file->name,
        $file->size,
        $file->type,
        $file->title,
        $file->datum,
        $file->description
    );

add the missing one s in 'sisss'

$query->bind_param(
            'sissss',
            $file->name,
            $file->size,
            $file->type,
            $file->title,
            $file->datum,
            $file->description
        );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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