WordPress: "Error saving media attachment"

Why such a useless error message? No explanation? Why can't fix itself? Why does a HTTP redirect?

(Using WordPress 3.0.1.)

Where's the code that generated the error?

  1. In lieu of debugging tools, I resorted to reading the code ;o).
  2. Assuming message isn't a translation, I can search:$ grep --recursive "Error saving" . ./wp-admin/upload.php:$messages[3] = __('Error saving media attachment.');
  3. Upload form rendered by: ./wp-admin/media-new.php → includes media-upload.php → renders a form (line 73) or calls one of the many media_upload_* actions in ./wp-admin/includes/media.php.
  4. All(?) these forms submitted to media-upload.php, with different query parameters
    1. → if "inline", calls (line 39) media_handle_upload("async-upload")
    2. → calls (media.php:95) wp_handle_upload (defined in ./wp-admin/includes/file.php:239)
    3. → which I guess returns an error (return array('error'=>$message);)
    4. → then media_handle_upload returns new WP_Error('upload_error',$file['error']) to media-upload.php
    5. → eventually calling (line 54) wp_redirect(admin_url('upload.php?message=3')), thereby losing the error details?!
  5. wp_handle_upload (./wp-admin/includes/file.php:239) triggers apply_filters('wp_handle_upload_prefilter',$file).
    1. Grep finds only one (built-in) such filter:./wp-admin/includes/ms.php:44:add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' );

      check_upload_size is defined in line 18.

      Hmm, but I have php_value upload_max_filesize 12M, and it was just a small image…

  6. file.php:330 calls wp_upload_dir → defined in ./wp-includes/functions.php:2123 → calls wp_mkdir_p (line 2178), which I guess is failing.

Cause and effect?

Allowing WP to create the "uploads" subdirectory, with permissions 0775, owned by www-data:www-data, this:

$ sudo chmod 0775 /var/www/$SITE/wp-content/ $ sudo chgrp www-data /var/www/$SITE/wp-content/

solves just one problem, ie, prevents the error.

Persistent, fundamental, failure

But the real problem runs much deeper.

  1. A Google search turns up 47K hits, dating from as early as 2009. It's 2011-02 now. Enough time, no?
  2. Why the HTTP redirect?
  3. Without the HTTP redirect, the error message still confuses most users:sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $uploads['path'] )
  4. Is the file system permissions issue so fundamental that it can't be solved once and for all?
  5. Why wasn't WP's handling of this issue improved: the error reporting, diagnostics, automation of the solution(s)… Ultimately, make it disappear.
  6. What would it take? Why is the process failing? Or is it? How to improve?

Notes

(None.)

(Appending notes disabled temporarily.)


Last modified 2011-02-20 16:16:12 +0000