[2024-08-16, MW 1.42.1]
Neither my solution below nor the $wgTmpDirectory solution someone else offered seem to work anymore.
Changing $wgTmpDirectory results in
RuntimeException: Could not open '<$wgTempDirectory contents>/mw-GlobalIdGenerator33-UUID-128'.
(...where by "<$wgTmpDirectory contents>" I mean the actual value of $wgTmpDirectory, not that literal string.)
...despite the fact that the directory given is writeable by the wiki's user.
I'm currently investigating, but I keep ending up in more jungle...
new info: Apache is running as the wrong user (www-data
instead of the user assigned by the domain's .conf file).
Since this is a problem with the Apache configuration and not MediaWiki, I'd consider this issue re-resolved. (It would be nice if the maintenance folder included some kind of diagnostic tool for image issues; figuring out that wrong-user was the issue came only after hours of exploring other options.)
[2012-06-07, MW 1.19.0]
I dove into the code and figured it out. The exact problem may be different from server to server, but in my case the problem was occurring at this line in /includes/filerepo/backend/TempFSFile.php:
$newFileHandle = fopen( $path, 'x' );
The value of $path is partly based on the global wfTempDir() function, defined in /includes/GlobalFunctions.php. This function does several checks to find a good temp folder for creating images; on my system, it failed to find anything in the environment and was falling back to sys_get_temp_dir(), which told it to use "/tmp".
This should have been valid, because that folder is world-writable and there are in fact temp files there... but when I told fopen() to use a different path, it started working.
What I did was to explicly set, in LocalSettings.php, one of the environment variables to point to a temp directory I had created in my account space:
putenv('TMPDIR=/path/to/my/temp/folder');
After that, everything was happy again.