We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

File Manager File Already Exists (when it doesn't)

Development and Programming

jtkendall's avatar
jtkendall
59 posts
about 13 years ago
jtkendall's avatar jtkendall

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:

  1. Upload file called test.pdf
  2. file_after_save is called 2a. It renames the file to 1367515559_test.pdf 2b. updates table row for test.pdf with it’s new name

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?

       
jtkendall's avatar
jtkendall
59 posts
about 13 years ago
jtkendall's avatar jtkendall

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?

       
avroo's avatar
avroo
164 posts
12 years ago
avroo's avatar avroo

Hi JT, I am running into exactly the same thing. Need to rename my files after upload, but because of that conditional it comes up with the “already exists-message”.

Did you found any solution?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.