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!

CommentFileSizeAuthor
file.inc_.patch550 bytesnacho.mg

Comments

mscdex’s picture

I was having this exact same problem. I applied the supplied patch and my file uploads in my form work perfectly now! Thanks!

drumm’s picture

Status: Needs review » Needs work

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.

dpearcefl’s picture

Status: Needs work » Closed (won't fix)

Due to the age of the last comment on this issue and due to the fact that D5 is no longer supported, I am closing this issue.