OiO.lk Blog PHP Why move_uploaded_file fails with inappropriate ioctl?
PHP

Why move_uploaded_file fails with inappropriate ioctl?


I have a very very strange problem.
I am using the jQuery-File-Upload from blueimp for uploading files. I use it for years on Windows and Linux.
Recently I used a new server (with AlmaLinux). Previously I was using PHP 5.6 and now I am using PHP 7.4 on this new server.

When I upload a file I receive this warning : move_uploaded_file(/path_to_webroot/img/image.jpg): failed to open stream: Inappropriate ioctl for device in /path_to_webroot/php/UploadHandler.php on line 1079.
I tried to upload the same image with a very basic upload form (without using jQuery-File-Upload) and the move_uploaded_file was successful so it is not a permission problem.
The strange thing comes now!
I found a workaround!

if ($uploaded_file && is_uploaded_file($uploaded_file)) {
                // multipart/formdata uploads (POST method uploads)
                if ($append_file) {
                    file_put_contents(
                        $file_path,
                        fopen($uploaded_file, 'r'),
                        FILE_APPEND
                    );
                } else {
                    $toto = print_r($file_path, true); //Workaround: this line avoids to the next line to fail
                    move_uploaded_file($uploaded_file, $file_path); //this is the line failing
                }
            }

I don’t understand why doing a print_r() helps to succeed moving file. Even if I do a var_dump it helps. If I just do an echo it doesn’t work.

I would like to avoid to do this workaround for fixing my problem because it’s not a solution for me. Someone has an idea why move_uploaded_file is failing? Maybe can I change something in php.ini configuration?



You need to sign in to view this answers

Exit mobile version