mysqli insert在上传大文件时不起作用

时间:2019-03-11 13:40:35

标签: php mysql mysqli

我有一个从未遇到过的怪异问题。当我上传一个小文件时,代码工作正常,但是当我上传大文件(105mb)时,查询无法正常工作,并给出了此输出

  

MySQL服务器已不存在-2006 ../ uploads / sermons / 2019.03.08-Bro-GK.mp3

$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);

1 个答案:

答案 0 :(得分:1)

您似乎正在遇到读取超时,因为上载花费的时间比脚本保持连接打开的时间长。尝试将MYSQLI_OPT_READ_TIMEOUT的值设置为类似mysqli_options($conn, MYSQLI_OPT_READ_TIMEOUT, value_in_seconds);的值。如果您遇到此错误https://bugs.php.net/bug.php?id=76703

,可能需要在实际连接之前设置$conn