Skorzystałem z dostępnego skryptu dodawania zdjęć na serwer i do bazy MySql jQuery File Upload
Przerobiłem go na moje potrzeby i działa rewelacyjnie lecz tylko w 99%.
Potrzebuję wprowadzić INSERTEM do bazy ID które przekazuję do jQuery File Upload z poprzedniej strony
<a href="upload/index.php?set_id=
<?php echo $query2['set_id']; ?>" class="btn yellow">
korzystałem wcześniej przy tego typu zabiegach z
$set_id = $_REQUEST['set_id'];
i w Insert podawałem wartość zmiennej i była przekazywana do bazy razem z linkiem
Niestety w przypadku tego skryptu wyskakuje błąd "nieprawidłowy token" przy dodawaniu zdjęcia i nie jest to już taka prosta sprawa
Poniżej główny skrypt jQFU
'delete_type' => 'POST',
'db_host' => 'localhost',
'db_user' => '',
'db_pass' => '',
'db_name' => '',
'db_table' => 'files'
);
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);
Jak poradzić sobie z tym problemem