jQuery-File-Upload
jQuery-File-Upload copied to clipboard
Unable to add file information to database
First of, I have read multiple times the PHP MySQL database integration page but I can't seem to get this working.
The only thing I want is to add the filenames and title in to a database. Nothing specials, so according to the quide I changed the index.php file like this:
<?php
$options = array(
'delete_type' => 'POST',
'db_host' => 'localhost',
'db_user' => 'user',
'db_pass' => 'pass',
'db_name' => 'db-name',
'db_table' => 'table'
);
require('UploadHandler.php');
class CustomUploadHandler extends UploadHandler {
protected function initialize() {
//$db = new mysqli('localhost','userwcg','vZ9yeUQztADp2DfC', 'thunnissen_kopersopties');
$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];
}
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']
.'` (`display_name`, `file_name`, `file_type``)'
.' VALUES (?, ?, ?)';
$query = $this->db->prepare($sql);
$query->bind_param(
'sss',
$file->title,
$file->name,
$file->type
);
$query->execute();
$file->id = $this->db->insert_id;
}
return $file;
}
}
$upload_handler = new CustomUploadHandler($options);
?>
As soon as I add the last line and test the upload of a file I get the following error:
SyntaxError: Unexpected token <
Any idea what I am doing wrong here?
Check the network tab of your browser (e.g. Chrome) to see the actual HTML error message sent back from your server.
Please also see #2190