php - Fileupload.js + MySQL -
i'm kinda new in php javascript/jquery... i'm developing system must handle uploads. using fileupload.js works but... can't retrieve file info , store @ mysql name,extension,size,url ... when try got error message:
syntaxerror: unexpected token <
the code starts problems is:
<?php $options = array( 'delete_type' => 'post', 'db_host' => 'localhost:3306', 'db_user' => 'root', 'db_pass' => '123456', 'db_name' => 'house', 'db_table' => 'midias' ); 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 `'.$this->options['db_table'] .'` (`name`, `size`, `type`, `title`, `description`)' .' values (?, ?, ?, ?, ?)'; $query = $this->db->prepare($sql); $query->bind_param( $file->name, $file->size, $file->type, $file->title, // try change $_session[userid] $file->description // try change dateofupload ); $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` `' .$this->options['db_table'].'` `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 $name => $deleted) { if ($deleted) { $sql = 'delete `' .$this->options['db_table'].'` `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);
i can't figure out whats happening, hope can give me light thank attention, , sorry huge code ;s
i experiencing same problem. couln't replace $file->anything
specific value. tried 3
, '3'
, "3"
... int
or string
. of returned same syntaxerror: unexpected token
my solution
$myvar = "hvhjvcvv"; $sql = 'insert `'.$this->options['db_table'] .'` (`randomfield`, `name`, `size`, `type`, `title`, `description`)' .' values (?, ?, ?, ?, ?, ?)'; $query = $this->db->prepare($sql); $query->bind_param('ssisss', $myvar, $file->name, $file->size, $file->type, $file->title, $file->description); $query->execute(); $file->id = $this->db->insert_id;
hope help.
also note bad db connection return same error ;)
Comments
Post a Comment