php mysqli插入失败,php – mysqli图像blob插入不起作用

本文介绍了一个使用PHP将图像文件上传到MySQL数据库的脚本。该脚本检查文件类型和大小,并使用mysqli扩展来插入图像数据。然而,在某些情况下,尽管脚本运行没有错误,上传的图像大小却显示为0字节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我正在尝试将图像文件上传到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

$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("Image to be uploaded is too large..Error uploading the image!!");

}

}else{

debug("Not a valid image file! Please upload jpeg or gif image.");

}

}else{

switch($_FILES['filename']['error']){

case 0: //no error; possible file attack!

debug("There was a problem with your upload.");

break;

case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini

debug( "The file you are trying to upload is too big.");

break;

case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form

debug( "The file you are trying to upload is too big.");

break;

case 3: //uploaded file was only partially uploaded

debug( "The file you are trying upload was only partially uploaded.");

break;

case 4: //no file was uploaded

debug( "You must select an image for upload.");

break;

default: //a default error, just in case!

debug( "There was a problem with your upload.");

break;

}

}

上传的图像似乎找到了护理脚本输出,但看着数据库大小是0字节…

有人知道为什么吗?

解决方法:

mysqli SEND_LONG_DATA()!!!

对于某些php / mysql(尤其是mysqli lib)服务器设置,Blob似乎特别令人沮丧.此解决方案似乎一直在配置设置无法解决问题.如果重新实施它的头痛我会建议PDO.

标签:php,blob,mysqli,insert

来源: https://codeday.me/bug/20190831/1775110.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值