Error When Moving Uploaded Files: “Inappropriate ioctl for device” and Synchronization Issues

What application are you using?
OJS 3.4.0-8

When attempting to upload files in the application, an error occurs while moving the temporary file to the target directory. The error shown in the logs is:

PHP Warning: move_uploaded_file(/var/www/vhosts/…/file_ojs_/temp/jpgoa6Bd0): Failed to open stream: Inappropriate ioctl for device
PHP Warning: move_uploaded_file(): Unable to move ‘/tmp/phpL0hO4B’ to ‘/var/www/vhosts/…/file_ojs_/temp/jpgoa6Bd0’

What I expected to happen:
The uploaded file should be moved correctly from the temporary directory (/tmp ) to the target directory (/var/www/vhosts//file_ojs_/temp ) without errors.

Steps I took leading up to the issue

  1. Logged into the OJS administration panel.
  2. Navigated to the “Manage Issues” section.
  3. Attempted to upload a file (e.g., a PDF) to include in a journal issue.
  4. The file was uploaded to the server, but when trying to move it to the target directory, the aforementioned error occurred.

What application are you using?

  • Application: Open Journal Systems (OJS)
  • Version: OJS 3.4.0-8
  • Environment:
    • Server: Apache/2.4.41 (Ubuntu)
    • PHP: 8.2
    • Plesk

Additional information

Relevant logs

Here are the PHP logs I captured before implementing a temporary fix:
[Date and time] PHP message: User running the script: admin_universitas
[Date and time] PHP message: Temporary file permissions: 0600
[Date and time] PHP message: Destination file permissions (existing): 0600
[Date and time] PHP message: File successfully moved to: /var/www/vhosts/…/file_ojs_/temp/jpgxf5tKV
[Date and time] PHP message: Setting mode for /var/www/vhosts/…/file_ojs_/temp/jpgxf5tKV with mask 438 and umask 18
[Date and time] PHP message: Final mask: 420

Additional observations

  • The issue appears to be related to race conditions or synchronization timing. When I add additional logs before the problematic code section, the error disappears, suggesting that the operating system needs more time to complete the operation.
  • I implemented a temporary fix by adding an artificial delay (sleep(1)) before moving the file, which resolved the issue. However, this is not an optimal solution.

Temporary solution

@lib/pkp/classes/file/Filemanager.php line 185
I added the following code before the move_uploaded_file call:
sleep(1); // 1-second delay to avoid race conditions
if (move_uploaded_file($_FILES[$fileName][‘tmp_name’], $destFileName)) {
return $this->setMode($destFileName, self::FILE_MODE_MASK);
}

Request for assistance

I need help identifying the root cause of the issue and a more robust solution that does not rely on artificial delays. Could this be related to PHP configuration, the file system, or OJS code?

Conclusion

The issue appears to be related to synchronization or execution timing when moving uploaded files. I would appreciate any guidance on how to resolve this issue permanently without relying on artificial delays.

Optional

This could be an option:
$maxAttempts = 5; // Número máximo de intentos
$attempt = 0;

while ($attempt < $maxAttempts) {
if (file_exists($_FILES[$fileName][‘tmp_name’]) && is_readable($_FILES[$fileName][‘tmp_name’])) {
if (move_uploaded_file($_FILES[$fileName][‘tmp_name’], $destFileName)) {
return $this->setMode($destFileName, self::FILE_MODE_MASK);
} else {
$error = error_get_last();
error_log("Error al mover el archivo: " . print_r($error, true));
return false;
}
} else {
$attempt++;
sleep(1); // Esperar 1 segundo antes de reintentar
}
}

error_log(“Error: El archivo temporal no está disponible después de $maxAttempts intentos.”);
return false;

Hi @PaideiaStudio,

I suspect this is being caused by a server-side virus scanner, which may be racing PHP to quarantine uploaded files. See this similar thread.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

This topic was automatically closed after 10 days. New replies are no longer allowed.