首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当上传大文件时mysqli插入不工作。

问当上传大文件时mysqli插入不工作。
EN

Stack Overflow用户
提问于 2019-03-11 13:40:35
回答 1查看 134关注 0票数 0

我以前从没面对过这个奇怪的问题。当我上传一个小文件时,代码运行良好,但是当我上传larg文件(105 me )时,查询不起作用,并给出了这个输出。

MySQL服务器已经消失- 2006 ./上传/布道/2019.03.08-兄弟-GK.mp3

代码语言:javascript
复制
$uploadDirectory = "../uploads/sermons/";
require '../includes/config.php'; // this contains the connection ($conn)
$errors = []; // Store all foreseen and unforseen errors here

$fileExtensions = ['mp3','wav']; // Get all the file extensions

$fileName = $_FILES['file']['name'];
$fileSize = $_FILES['file']['size'];
$fileTmpName  = $_FILES['file']['tmp_name'];
$fileType = $_FILES['file']['type'];
$fileExtension = explode('.',$fileName);
$fileExtension = end($fileExtension);
$fileExtension = strtolower($fileExtension);

$uploadPath = $uploadDirectory . basename($fileName);


    if (! in_array($fileExtension,$fileExtensions)) {
        $errors[] = "This file extension is not allowed. Please upload a mp3 or wav file";
    }



    if (empty($errors)) {
        $didUpload = move_uploaded_file($fileTmpName, $uploadPath);

        if ($didUpload) {

            $title = mysqli_real_escape_string($conn,$_POST["Title"]);
            $speaker = mysqli_real_escape_string($conn,$_POST["Speaker"]);
            $date = mysqli_real_escape_string($conn,$_POST["date"]);
            $date = date('Y-m-d', strtotime($date));
            $description = mysqli_real_escape_string($conn,$_POST["Description"]);
            $query = "Insert into `sermons` (`Title`,`Description`,`Speaker`,`Date`,`Link`) values('$title','$description','$speaker','$date','$uploadPath');";
            $result = mysqli_query($conn,$query) or die(mysqli_error($conn)." - ".mysqli_errno($conn)." ".$uploadPath);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-11 13:53:34

似乎您正处于读超时状态,因为上传所用的时间比脚本保持连接打开所需的时间长。尝试将MYSQLI_OPT_READ_TIMEOUT的值设置为类似于so mysqli_options($conn, MYSQLI_OPT_READ_TIMEOUT, value_in_seconds);的值。在实际连接之前,您可能需要设置$conn,以防您遇到这个bug https://bugs.php.net/bug.php?id=76703

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55103148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档