file_save_upload function does not work as expected

trasgu - March 23, 2007 - 15:23
Project:Drupal
Version:5.x-dev
Component:base system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:patch (code needs work)
Description

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!

AttachmentSize
file.inc_.patch550 bytes

#1

mscdex - May 10, 2007 - 01:37

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

#2

drumm - November 12, 2007 - 04:14
Status:patch (code needs review)» patch (code 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.

 
 

Drupal is a registered trademark of Dries Buytaert.