class.upload.php 在 CentOS 7.6 LEMP droplet 中失败

class.upload.php failing in CentOS 7.6 LEMP droplet

长话短说:

我在 LEMP 实例中的 Amazon Web Services 中托管我的 MVC PHP 应用程序。

然后我决定转移到 Digital Ocean,因为他们的实例不允许发送电子邮件。

我的应用程序在 AWS 实例中能够上传照片、写入数据库并与外部通信 API。

然而,在 Digital Ocean 中,我无法使用 class.upload.php 上传照片。在 /var/log/nginx/error.log 中,这是输出:

2020/05/18 03:28:17 [error] 10851#0: *174 FastCGI sent in stderr: "PHP message: PHP Notice:  A non well formed numeric value encountered in /usr/share/nginx/html/admin/core/controller/class.upload.php on line 2667 PHP message: PHP Notice:  A non well formed numeric value encountered in /usr/share/nginx/html/admin/core/controller/class.upload.php on line 2667" while reading response header from upstream, client: 181.115.109.228, server: _, request: "POST /admin/index.php?action=addproduct HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "165.227.91.80", referrer: "http://165.227.91.80/admin/index.php?view=newproduct"

你会认为第 2667 行的 class.upload.php 有错误,但事实并非如此。正如我告诉您的那样,AWS 中的一切都按预期运行。 /var/log/php-fpm/error.log 没有显示任何错误。这是输出:

[18-May-2020 01:39:40] NOTICE: fpm is running, pid 10826
[18-May-2020 01:39:40] NOTICE: ready to handle connections
[18-May-2020 01:39:40] NOTICE: systemd monitor interval set to 10000ms

上传目录是/usr/share/nginx/html/admin/storage我设置的权限是777。 我可能做错了什么? 我的 PHP 版本是 PHP 7.3.18 (cli). 这是将产品添加到数据库的 PHP 代码。

$product = new ProductData();
    foreach ($_POST as $k => $v) {
       if($k=="existence"){
           if($v==""){
            $product->existence=12;
           }else{
            $product->$k = $v;
           }
       }else{
        $product->$k = $v;

       }
    }

    $alphabeth = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ1234567890_-";
    $code = "";
    for ($i = 0;$i < 11;$i++) {
        $code.= $alphabeth[rand(0, strlen($alphabeth) - 1) ];
    }
    $product->short_name = $code;
    $handle = new Upload($_FILES['image']);
    if ($handle->uploaded) {
        $url = "storage/products/";
        $handle->Process($url);
        $product->image = $handle->file_dst_name;
    }
    if (isset($_POST["is_public"])) {
        $product->is_public = 1;
    } else {
        $product->is_public = 0;
    }
    if (isset($_POST["in_existence"])) {
        $product->in_existence = 1;
    } else {
        $product->in_existence = 0;
    }
    if (isset($_POST["is_featured"])) {
        $product->is_featured = 1;
    } else {
        $product->is_featured = 0;
    }
    if (isset($_POST["doublePoints"])) {
        $product->doublePoints = 1;
    } else {
        $product->doublePoints = 0;
    }
    // $product->name = $_POST["name"];
    $product->add();
    Core::redir("index.php?view=products");

SELinux 在 AWS 实例中是 disabled,在 DigitalOcean 中是 enforcing。 我只需要禁用它才能上传文件。