class.upload.php failing in CentOS 7.6 LEMP droplet

58 views Asked by At

Long story short:

I was hosting my MVC PHP application in Amazon Web Services in a LEMP Instance.

I then decided to move to Digital Ocean because their instances are not allowed to send emails.

My app, in the AWS instance, was able to upload photos, write to the database, and communicate with an external API.

In Digital Ocean, however, I’m not able to upload photos with class.upload.php. In /var/log/nginx/error.log this is the output:

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"

You’d believe that there’s an error in class.upload.php on line 2667, however, this is not the case. As I’m telling you, everything works as intended in AWS. /var/log/php-fpm/error.log does not show any error. This is the output:

[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

The upload directory is /usr/share/nginx/html/admin/storage I've set the permissions are set to 777. What could I be doing wrong?. My PHP version is PHP 7.3.18 (cli). This is the PHP code that adds a product to the database.

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

There are 1 answers

0
AudioBubble On BEST ANSWER

SELinux was disabled in the AWS instance and enforcing in DigitalOcean. I just had to disable it in order to upload files.