I'm trying to force replacement of existing file with same name, if a new version is uploaded by user. I've seen a lot of posts about this topic but none that I could find addresses how to force the replacement.
I'm using a custom form, and here's the code I've been trying to make work during the form validation:
$file = file_save_upload( 'file', array( 'file_validate_is_document' => array(), // Validates file is really a document. 'file_validate_extensions' => array('pdf doc ppt pps avi mpg mov wmv'), // Validate extensions. ), 'public://', FILE_EXISTS_REPLACE );
The revised file (let's say "file.jpg") is uploaded, but inevitably Drupal creates a new copy and renames it file_0.jpg, file_1.jpg, etc for each new version.
I even tried to programmatically delete the original file using "file_delete" prior to committing the upload but I still get the copy!
Any help would be appreciated.