file_save_upload function does not work as expected
| Project: | Drupal |
| Version: | 5.x-dev |
| Component: | base system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | patch (code needs work) |
Jump to:
In the file_save_upload documentation (and also in any other version) you can read, in the parameters explain:
$replace A boolean, set to true if the destination should be replaced when in use, but when false append a _X to the filename.
But if you pass this parameter to the function as boolean TRUE value, you will get an error. This is because file_save_upload calls file_move, that calls file_copy. If you pass $replace as TRUE to file_copy, in the switch statement it will falls to first case != 0, ie: case FILE_EXISTS_ERROR, but case FILE_EXISTS_REPLACE is expected
As log as I think that $replace=TRUE | FALSE in file_save_upload makes sense, and I think that is file_move the function that is not working as expected, I'd add some code to the switch statement in file_move to fix this. (see patch)
greetings!
| Attachment | Size |
|---|---|
| file.inc_.patch | 550 bytes |

#1
I was having this exact same problem. I applied the supplied patch and my file uploads in my form work perfectly now! Thanks!
#2
Actually, the documentation is wrong for file_save_upload(). The $replace argument's documentation should match file_save_data(), file_copy(), and file_move() and suggest using the constants.