The file.inc in Drupal core utilizes the PHP tempnam() function in a couple of places to obtain a temporary filename.
With the format of tempnam($dir, $prefix), it should create a temporary file in directory $dir. However, in Windows, this MUST be an absolute path. If a relative path is used, then it defaults to the system temp (i.e. $_ENV['TMP']).
(See http://www.php.net/manual/en/function.tempnam.php#67260)
This confuses file_check_upload() in file.inc since it expects the uploaded file to be in this location.
This has manifested itself in bizarre ways, such as in uploads using the image module.
(See http://drupal.org/node/178013)
The solution is to force an absolute path when calling tempnam():
tempnam(realpath(file_directory_temp()), 'tmp_');
The attached patch does this.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | file_tempnam_180126.patch | 1.3 KB | drewish |
| #6 | file_180126_3.patch | 788 bytes | scor |
| #5 | file_180126_0.patch | 973 bytes | drewish |
| #3 | file_180126_2.patch | 674 bytes | scor |
| #2 | file_180126.patch | 675 bytes | drewish |
Comments
Comment #1
drewish commentedsubscribing. i'll try to have a look at this later on.
Comment #2
drewish commentedShort version of the bug report is that we're writing to the wrong temp directory.
Bumping this to D6 since it affects file_save_data() there. Once we get it committed we can back port to D5.
Comment #3
scor commentedrerolled the patch from drupal root.
tested with css and js aggregator.
Comment #4
gábor hojtsyThis is an obscure requirement from Windows versions, so document it above the line with some comment:
// On Windows, temnap() requires an absolute path, so we use realpath().
Or something along these lines.
Comment #5
drewish commentedAdded the comment that Gabor requested.
Comment #6
scor commentedAdded and corrected the comment that Gabor requested ;)
Comment #7
drewish commentedscor, did we cross-post or did you just not like my more info link?
Comment #8
gábor hojtsyThanks, committed.
Comment #9
scor commentedBoth :)
the right spelling of the function is tempnam() not temnap()...
Comment #10
scor commentedcross posting...
Comment #11
(not verified) commentedComment #12
CheckeredFlag commenteddrewish, just following up. Any word on getting this fix back ported to drupal 5 as per your comment #2?
Comment #13
drewish commentedyeah we need to flag it for back port... i'll try to check on the patch later today.
Comment #14
drewish commentedmmoreno, give this a look/try.
Comment #15
CheckeredFlag commentedWorked well on Drupal 5.5. Thanks!
Comment #16
CheckeredFlag commenteddrewish, just following up again after testing your patch as I'll be out after today until after the new year....
Comment #17
drummCommitted to 5.x.
Comment #18
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.