I’m working on a EE2 extension for the file manager that adds a few additional fields to the files database table and then populates them during the file_after_save hook. This includes updating the file_name field after renaming the file on the server (prepending time()) so if they accidentally upload a file with the same name there’s no issue and they don’t have to deal with renaming.
This all works until I try to upload the same file again to test it, it then throws a file already exists error even though the uploaded file has successfully been renamed and the database row has been successfully. There is literally no mention of the old file name in the database table or as a file in the uploads folder.
So the basic process is:
I try to repeat the process and it says that ‘test.pdf’ already exists.
Any ideas what could cause it to say a file exists when it doesn’t?
Ok, I figured out the issue, it’s this conditional in content_files_modal.php
if ($file['file_name'] != $original_name
AND $file['file_name'] != $cleaned_name)
{
// At this point, orig_name contains the extension
$vars = $this->_vars_rename($file, $original_name);
return $this->load->view('_shared/file_upload/rename', $vars);
}Since I’m changing the $file_name during file_after_save the $file_name will never match $cleaned_name or $original_name, but what doesn’t make sense to me is why this check is being performed after file_after_save? The file has already saved, why does it need to make this check in a hook that’s supposed to run after it’s already done the save?
Is there anyway to override content_files_modal.php without changing the core files?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.