php – mysqli图像blob插入不起作用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – mysqli图像blob插入不起作用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2722字,纯文字阅读大概需要4分钟。
内容图文
![php – mysqli图像blob插入不起作用](/upload/InfoBanner/zyjiaocheng/893/64299a4960a5412ebe11c29c35dda642.jpg)
我正在尝试将图像文件上传到MySql数据库.我已经在网上发布了seacrh,最后我开始使用以下脚本:
if(is_uploaded_file($_FILES['filename']['tmp_name'])){
$maxsize=$_POST['MAX_FILE_SIZE'];
$size=$_FILES['filename']['size'];
// getting the image info..
$imgdetails = getimagesize($_FILES['filename']['tmp_name']);
$mime_type = $imgdetails['mime'];
// checking for valid image type
if(($mime_type=='image/jpeg')||($mime_type=='image/gif')||($mime_type=='image/png')){
// checking for size again
if($size<$maxsize){
$filename=$_FILES['filename']['name'];
$imgData =addslashes (file_get_contents($_FILES['filename']['tmp_name']));
if(is_uploaded_file($_FILES['filename']['tmp_name'])){
debug('subida ok');
}else{
debug('fallo subida');
}
//echo $imgData;
$imgDetail=addslashes($imgdetails[3]);
$db = new mysqli('127.0.0.1','user','pass', 'db');
if($db->connect_error){
debug('Error en la conexion : '.$db->connect_errno.
'-'.$db->connect_error);
}
$stmt = $db->stmt_init();
$stmt->prepare("INSERT INTO `image` (`name`, `image`, `type`, `size`) VALUES (?, ?, ?, ?)");
if($stmt===false){ debug('Error en prepare');}
$rc=$stmt->bind_param('sbss', $filename, $imgData, $mime_type,$imgDetail);
if($rc===false){ debug('Error en bind');}
if($stmt->execute()==false){ debug('error ' . $stmt->error); };
$stmt->close();
}else{
debug("<font class='error'>Image to be uploaded is too large..Error uploading the image!!</font>");
}
}else{
debug("<font class='error'>Not a valid image file! Please upload jpeg or gif image.</font>");
}
}else{
switch($_FILES['filename']['error']){
case 0: //no error; possible file attack!
debug("<font class='error'>There was a problem with your upload.</font>");
break;
case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
debug( "<font class='error'>The file you are trying to upload is too big.</font>");
break;
case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
debug( "<font class='error'>The file you are trying to upload is too big.</font>");
break;
case 3: //uploaded file was only partially uploaded
debug( "<font class='error'>The file you are trying upload was only partially uploaded.</font>");
break;
case 4: //no file was uploaded
debug( "<font class='error'>You must select an image for upload.</font>");
break;
default: //a default error, just in case!
debug( "<font class='error'>There was a problem with your upload.</font>");
break;
}
}
上传的图像似乎找到了护理脚本输出,但看着数据库大小是0字节…
有人知道为什么吗?
解决方法:
mysqli SEND_LONG_DATA()!!!
http://php.net/manual/en/mysqli-stmt.send-long-data.php
对于某些php / mysql(尤其是mysqli lib)服务器设置,Blob似乎特别令人沮丧.此解决方案似乎一直在配置设置无法解决问题.如果重新实施它的头痛我会建议PDO.
内容总结
以上是互联网集市为您收集整理的php – mysqli图像blob插入不起作用全部内容,希望文章能够帮你解决php – mysqli图像blob插入不起作用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。