【问题标题】:Mysql server has gone away while storing large (2MB) audio file in LONGBLOB在 LONGBLOB 中存储大 (2MB) 音频文件时,Mysql 服务器消失了
【发布时间】:2015-04-14 01:43:16
【问题描述】:

我想在mysql 数据库中存储一个音频文件。我正在使用LONGBLOB 存储此音频文件的base64 编码字符串。但正如我执行查询时,我收到此警告,但没有在数据库中插入:

Warning: mysql_query() [function.mysql-query]: MySQL server has gone away 

当我上传任何图像文件时,我没有收到任何错误,并且代码工作正常。当我上传视频和音频文件时会发生这种情况。在我正在使用的代码中:

<?php
    include 'database_handler.php';
    if(isset($_FILES['fileToUpload']['name'])){
    echo "uploading. . .";
    $file = rand(0, 10000000).$_FILES['fileToUpload']['name'];
    if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $file)) {
        if($fp = fopen($file,"rb", 0))
        {
           $picture = fread($fp,filesize($file));
           fclose($fp);
           $base64 = base64_encode($picture);
           //echo $base64;
           $db = new Database();
           $db->test($base64);
        }
    }
}
?>
<form action="test.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

这是我正在调用的函数代码:

function test($base64String){
    if (mysql_query("update users set attribute1='$base64String' where id = '83'")){
                    echo "success";

                }else{
                    mysql_error();
                }
}

谢谢

【问题讨论】:

    标签: php mysql audio file-upload


    【解决方案1】:

    请加/etc/mysql/my.cnf,

    wait_timeout = 3600
    

    max_allowed_packet = 128M
    

    然后重启

    sudo /etc/init.d/mysql restart
    

    注意:为什么将音频文件存储在数据库中,而不是存储它的路径并将文件存储在系统中

    【讨论】:

    • 谢谢。我的 wamp 服务器中没有 my.cnf 这样的文件。
    • my.ini?查看图片:i.stack.imgur.com/gNvLC.png。你也从那里重新启动服务
    • 嘿,从 100M 更改 max_allowed_pa​​cket = 128M 刚刚解决了我的问题。我在 my.ini 中进行了此更改。另外我没有在 my.ini 中找到 wait_timeout
    • 对不起,先生,但我说 my.cnf。一样吗??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-27
    • 2010-09-14
    • 2012-08-13
    • 1970-01-01
    • 2012-08-27
    • 2018-03-10
    相关资源
    最近更新 更多