0

长话短说:

我在 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");
4

1 回答 1

0

SELinuxdisabled在 AWS 实例和enforcingDigitalOcean 中。我只需要禁用它才能上传文件。

于 2020-05-19T21:29:14.430 回答