Home  >  Article  >  Backend Development  >  jquery-file-upload 的php mysql插入有关问题

jquery-file-upload 的php mysql插入有关问题

WBOY
WBOYOriginal
2016-06-13 12:04:52828browse

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 />);



应该就是这段了....

我尝试多次,加入url字段都不成功 [原本的文档代码]
<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 />    }


都给我显示:
Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in

这是什么意思,说我的数量有问题? 是指我加少了吗?
我已经改成...这样,5处的type字段也都加了url也说是数量问题?

<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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn