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?
- In lieu of debugging tools, I resorted to reading the code ;o).
- Assuming message isn't a translation, I can search:
$ grep --recursive "Error saving" . ./wp-admin/upload.php:$messages[3] = __('Error saving media attachment.'); - 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. - All(?) these forms submitted to media-upload.php, with different query parameters
- → if "inline", calls (line 39)
media_handle_upload("async-upload") - → calls (media.php:95)
wp_handle_upload(defined in ./wp-admin/includes/file.php:239) - → which I guess returns an error (
return array('error'=>$message);) - → then media_handle_upload returns
new WP_Error('upload_error',$file['error'])to media-upload.php - → eventually calling (line 54)
wp_redirect(admin_url('upload.php?message=3')), thereby losing the error details?!
- → if "inline", calls (line 39)
wp_handle_upload(./wp-admin/includes/file.php:239) triggersapply_filters('wp_handle_upload_prefilter',$file).- 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_sizeis defined in line 18.Hmm, but I have
php_value upload_max_filesize 12M, and it was just a small image…
- Grep finds only one (built-in) such filter:
- file.php:330 calls
wp_upload_dir→ defined in ./wp-includes/functions.php:2123 → callswp_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:
solves just one problem, ie, prevents the error.
Persistent, fundamental, failure
But the real problem runs much deeper.
- A Google search turns up 47K hits, dating from as early as 2009. It's 2011-02 now. Enough time, no?
- Why the HTTP redirect?
- 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'] ) - Is the file system permissions issue so fundamental that it can't be solved once and for all?
- Why wasn't WP's handling of this issue improved: the error reporting, diagnostics, automation of the solution(s)… Ultimately, make it disappear.
- 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