0

When trying to upload files to the Wordpress media library I encounter the following error:

Unexpected response from the server. The file may have been uploaded successfully. Check in the Media Library or reload the page.

I enabled debugging mode in WP by adding

define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', true);
define('WP_DEBUG_LOG', true);

to my wordpress config file.

After taking a look at debug.log there seems to be a problem with one of the WP core files PHP Fatal error: Uncaught Error: Cannot unset string offsets

The full debug log

The function throwing the error is clean_dirsize_cache

Line 8381: unset( $directory_cache[ $path ] );

I've already tried the following:

  • Allocated more memory in php.ini
  • Changed limit for max file sizes

The error happens on every file I try to upload, file size or file type doesn't seem to matter.

As I'm not experienced with Wordpress and I haven't worked on this site previously at all I'm not quite sure what caused this to start occuring.

1 Answer 1

1

I have the same issue on only one of the three wordpress sites managed by a multisite wordpress. I am not experienced with Wordpress either, but I have managed to get uploads working by replacing

if ( empty( $directory_cache ) ) {
    return;
}

by

if ( empty( $directory_cache ) || !is_array($directory_cache) ) {
    return;
}

at line 8368 in wp-includes/functions.php

I have not yet encountered any inconvenience with this change but it still might have some unexpected implications.

2
  • 2
    Note that, if you modify core files, there's a strong possibility your changes will be overwritten in a future update. See What are some reasons you should not modify core files? for more information and suggestions.
    – Pat J
    Commented Oct 20, 2022 at 18:55
  • This should not be the accepted answer, as it will simply break again the next time WP updates.
    – vancoder
    Commented Nov 2, 2022 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.