I've written a patch to change the way that Drupal handles file uploads. Presently, when a user uploads a file such as win32-binary.zip and that file already exists in the files directory, Drupal will automatically rename the file to win32-binary_0.zip. This is ugly, and violates Drupal's idea of clean URLs, as it changes the file name from a good default (win32-binary.zip) to a poor one (win32-binary_0.zip). In addition, it flat-out breaks tar.gz files: source.tar.gz will be renamed to source.tar_0.gz, which many archivers will not open correctly.
The patch I have attached here will change the way Drupal renames files. Instead of putting uploaded files into files/win32-binary.zip (for example), it will instead place them into files/0/win32-binary.zip. If this file exists, it will be placed in files/1/win32-binary.zip instead, and so on, counting upwards until a directory is found suitable.
Applying this patch will not affect current download links on your site, but newly attached files will use the newer path format.
Patch available at .
diff -ur drupal-5.1-base/includes/file.inc drupal-5.1/includes/file.inc
--- drupal-5.1-base/includes/file.inc 2007-01-05 00:32:22.000000000 -0500
+++ drupal-5.1/includes/file.inc 2007-06-03 17:53:43.908113168 -0400
@@ -341,7 +341,20 @@