php – 在遗留MySQL驱动程序中插入BLOB会导致“消失”错误

我按照this教程制作了一个图像上传器.它工作正常,除非我尝试上传更大的文件大小:它只是将文件大小“更改”为64KB并且只显示较大图像的一小部分.所以,我用Google搜索并发现’blob’的最大文件大小为64kb,因此我将其更改为longblob,其最大文件大小为4GB.

但现在,尝试上传大图像(1MB或更大),我得到sql错误MysqL服务器已经消失’.对于小于1MB的图像,上传工作.上传文件大小为915kb的1400×900图像,但文件大小为1.6mb的1400×900图像不上传.上传一个250×179的gif,文件大小为1mb.看起来如果文件大小大于1MB,PHP中的sql插入函数就不再连接了:这怎么可能?

我的PHP.ini的最大文件大小为32MB,所以这不是问题.我正在使用MAMP.

HTML:

PHP" method="POST" enctype="multipart/form-data"> File:

PHP

// connect to database
include 'include/config.PHP'; 

// file properties
$file = $_FILES['image']['tmp_name'];

if (!isset($file)){
    echo "Please select an image.";
} else {
    $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
    $image_name = addslashes($_FILES['image']['name']);
    $image_size = getimagesize($_FILES['image']['tmp_name']);

    if ($image_size==FALSE){
        echo "This is not an image";    
    }else{
        if(!$insert = MysqL_query("INSERT INTO gallery VALUES ('','$image_name','$image')")){
            die(MysqL_error());
            echo "Problem uploading the image.";
        }else{
            $lastid = MysqL_insert_id();
            echo "Image uploaded.

PHP?id=$lastid>"; } } }

PHP配置:

//database credentials
$username = "root";
$password = "root";
$hostname = "localhost"; 

//connection to the database
MysqL_connect($hostname,$username,$password) or die(MysqL_error()); 
MysqL_select_db('imandra') or die(MysqL_error()); 
//echo "Connected to MysqL";

PHP得到:

include 'config.PHP'; 

$id= addslashes($_REQUEST['id']);

$image = MysqL_query("SELECT * FROM gallery WHERE id='$id'");
$image = MysqL_fetch_assoc($image);
$image = $image['image'];

header("Content-type: image/jpeg");

echo $image;
最佳答案
您可能需要查看MysqL配置文件(my.cnf)中的设置.

增加max_allowed_pa​​cket设置的大小,例如

max_allowed_packet=50M

相关文章

vue阻止冒泡事件 阻止点击事件的执行 <div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些