move_uploaded_file not working in AlmaLinux 9.2

48 Views Asked by At

I don't understand what's wrong, everything looks correct, both from permissions, file locations, file names and functions

     $folderPath = __DIR__ . "/assets/img/upload/";

            $gambar = $_FILES['img'];

            if (!file_exists($folderPath)) mkdir($folderPath);

            if (file_exists($folderPath . $gambar["name"])) {
                return $gambar["name"] . " already in folder! ";
            } else {

                $sourcePath = $gambar['tmp_name']; 

                $acak           = rand(11111111, 99999999);
                $NewImageName   = str_replace(' ', '', 'gambar' . $acak  . '.' . $file_extension);

                $targetPath = $folderPath . $NewImageName; 
                $move = move_uploaded_file($sourcePath, $targetPath); 

                if (!$move) {
                    $respon = [
                        "status" => false,
                        "msg" => "Simpan berkas Gambar gagal!",
                        "name" => $NewImageName,
                        "source" => $sourcePath,
                        "location" => $targetPath,
                        "gambar_info" => $gambar,
                    ];

                    print_r($respon);
                    die();
                }
            }

Folder Permission

php.ini

file_uploads = On

upload_max_filesize = 2M

max_file_uploads = 20

response given

Result

The file should be successfully moved to the "upload" folder as in $targetPath

0

There are 0 best solutions below