jquery-file-upload 的php mysql插入問題
最近用jquery-file-upload 來改善網站上傳的體驗
https://github.com/blueimp/jQuery-File-Upload/wiki/PHP-MySQL-database-integration
上傳時按照他的參考文檔,立馬就完成了,一開始也按照他的sql 架構先試試
結果上傳後,也能成功插入,json傳回頁面一切正常!
但問題來了,他的sql 架構...有個叫url
但作者好像在PHP的SQL中沒有處理
那我就改改吧,....
先新增了一些基本配置
$dir = $_COOKIE["uid"].'/'.date("Y").'/'.date("m").'/'.date("d").'/';
$dirUP = "../../../att/".$dir;
$dirLink = $dir;
$options=array(
'upload_dir' => $dirUP,
'upload_url' => $dirLink,
'delete_type' => 'POST',
'db_host' => 'localhost',
'db_user' => 'root',
'db_pass' => '*****',
'db_name' => '*****',
'db_table' => 'files'
);
應該就是這段了....
我嘗試多次,加入url欄位都不成功 [原本的文檔代碼]
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;
}
都給我顯示:
Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in
這是什麼意思,說我的數量有問題? 是指我加少了嗎?
我已經改成...這樣,5處的type欄位也都加了url也說是數量問題?
protected function handle_file_upload($uploaded_file, $name, $size, $type,$url, $error,
$index = null, $content_range = null) {
$file = parent::handle_file_upload(
$uploaded_file, $name, $size, $type,$url, $error, $index, $content_range
);
if (empty($file->error)) {
$sql = 'INSERT INTO `'.$this->options['db_table']
.'` (`name`, `size`, `type`, `url`, `title`, `description`)'
.' VALUES (?, ?, ?, ?,? , ?)';
$query = $this->db->prepare($sql);
$query->bind_param(
'sisss',
$file->name,
$file->size,
$file->type,