Home > Article > Backend Development > jquery-file-upload 的php mysql插入有关问题
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").'/';<br />$dirUP = "../../../att/".$dir;<br />$dirLink = $dir;<br /><br />$options=array(<br /> 'upload_dir' => $dirUP,<br /> 'upload_url' => $dirLink,<br /> 'delete_type' => 'POST',<br /> 'db_host' => 'localhost',<br /> 'db_user' => 'root',<br /> 'db_pass' => '*****',<br /> 'db_name' => '*****',<br /> 'db_table' => 'files'<br />);
<br /> protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,<br /> $index = null, $content_range = null) {<br /> $file = parent::handle_file_upload(<br /> $uploaded_file, $name, $size, $type, $error, $index, $content_range<br /> );<br /> if (empty($file->error)) {<br /> $sql = 'INSERT INTO `'.$this->options['db_table']<br /> .'` (`name`, `size`, `type`, `title`, `description`)'<br /> .' VALUES (?, ?, ?, ? , ?)';<br /> $query = $this->db->prepare($sql);<br /> $query->bind_param(<br /> 'sisss',<br /> $file->name,<br /> $file->size,<br /> $file->type,<br /> $file->title,<br /> $file->description<br /> );<br /> $query->execute();<br /> $file->id = $this->db->insert_id;<br /> }<br /> return $file;<br /> }
<br> protected function handle_file_upload($uploaded_file, $name, $size, $type,$url, $error,<br> $index = null, $content_range = null) {<br> $file = parent::handle_file_upload(<br> $uploaded_file, $name, $size, $type,$url, $error, $index, $content_range<br> );<br> if (empty($file->error)) {<br> $sql = 'INSERT INTO `'.$this->options['db_table']<br> .'` (`name`, `size`, `type`, `url`, `title`, `description`)'<br> .' VALUES (?, ?, ?, ?,? , ?)';<br> $query = $this->db->prepare($sql);<br> $query->bind_param(<br> 'sisss',<br> $file->name,<br> $file->size,<br> $file->type,<div class="clear"> </div>