Title: File Attachment Error
Last modified: October 12, 2025

---

# File Attachment Error

 *  [pmarchand](https://wordpress.org/support/users/pmarchand/)
 * (@pmarchand)
 * [8 months ago](https://wordpress.org/support/topic/file-attachment-error-4/)
 * We are having some issues with our site that is hosted with WordPress VIP, where
   every form we have with Contact Form 7 that has a file attachment on it doesn’t
   work on submit.
 * I reached out to VIP support, where they essentially told us that we could look
   at doing some manual updates to the plugin, however these would end up getting
   rewritten/scrapped everytime we updated the plugin, which is not ideal.
 * Here was what support said:
 * ——————————–
 * We’ve tracked the issue you raised to [incompatibilities with the VIP File System](https://docs.wpvip.com/plugins/incompatibilities/#6-plugins-that-attempt-to-create-intermediate-images:~:text=The%20plugins%20listed%20below%20are%20not%20fully%20compatible%20with%20the%20VIP%20Platform.).
   
   The problem, from a high level (i.e., the line of code that breaks things), is
   that the `wpcf7_maybe_add_random_dir` function attempts to create a directory,
   but the function behaves in a way that’s unexpected (on VIP’s platform) due to
   code that the function runs (more on this below). Theoretically, a workaround
   for that is to simply comment out [this line](https://github.com/wpcomvip/nationalfuel-com/blob/ec506a1754d902818193294996797e50ad02a5e3/plugins/contact-form-7/includes/file.php#L53)
   utilizing the function.However, it’s difficult to say whether that is a reliable
   fix, whether it will introduce other problems, or whether it’s even a useful 
   solution, as plugin updates will typically overwrite modifications to the plugin
   code. Previously, we’ve [addressed issues with the directory structure](https://github.com/Automattic/vip-go-mu-plugins-built/blob/a8ae20dfa231ad9118af376825f6a513e76ebae1/plugin-fixes.php#L33)
   so that the CF7 plugin functions in a way that’s compatible with our platform,
   but our ability to do so relied on a filter that existed within the plugin already.
   For this specific problem, there’s no filter that we can leverage that would 
   allow us to apply a fix. However, one potential path forward might be for the
   plugin developer to add a filter [here](https://github.com/wpcomvip/nationalfuel-com/blob/ec506a1754d902818193294996797e50ad02a5e3/plugins/contact-form-7/includes/file.php#L53),
   which could open up reliable options for a fix to this specific problem on our
   platform, but again, it may introduce others, and whether adding a filter is 
   an option is something that their developers would more readily know than anyone
   from our side would.To elaborate more on the [specific code](https://github.com/wpcomvip/nationalfuel-com/blob/ec506a1754d902818193294996797e50ad02a5e3/plugins/contact-form-7/includes/file.php#L304-L320)
   within the `wpcf7_maybe_add_random_dir` function that’s problematic, the issue
   stems from the use of `file_exists`. The reason that’s problematic is a result
   of what’s mentioned in our documentation [here](https://docs.wpvip.com/vip-file-system/media-uploads/#:~:text=Because%20directories%20are%20created%20automatically%2C%20it%20is%20not%20necessary%20to%20add%20logic%20in%20code%20to%20check%20if%20a%20directory%20exists.%20If%C2%A0file_exists()%20is%20used%20in%20code%C2%A0to%20check%20if%20a%20directory%20exists%2C%20it%20will%20always%20return%20true%20for%20paths%20within%C2%A0/wp%2Dcontent/uploads/.)–
   i.e., if `file_exists()` is used in code to check if a directory exists, it will
   _always_ return `true` for paths within `/wp-content/uploads/`.Because the use
   of `file_exists` always returns true, its implementation within the function (
   where it tries to create a random directory) causes an infinite loop, and ultimately
   leads to the continuous spinner with no successful submission that you pointed
   out when opening the ticket.Similar to the potential workaround of simply commenting
   out the line that breaks things, there might be some way to modify the function’s
   use of `file_exists`, but at best, that’s a short-term potential solution that’s
   overridden each time the plugin is updated.So, to summarize, it’s likely there
   are custom solutions that modify some aspect of the plugin’s code in a way that
   works on our platform and addresses your issue, but we don’t typically recommend
   that sort of approach, given it’s less of a solution and more of a temporary 
   workaround, in which there are other new problems that could arise.With all of
   the above points in mind, there’s no apparent resolution that’s viable or ideal,
   leaving only a couple of avenues that might act as a long-term solution:
    - With the examples of incompatibilities between plugins and our file system
      in mind, find another plugin that satisfies the functionality your site needs
    - Work with the CF7 plugin team to implement a change that allows more flexibility
      to customize plugin behavior, especially as it pertains to the uploads directory
       * As mentioned above, one thought that comes to mind might be to add a filter
         [here](https://github.com/rocklobster-in/contact-form-7/blob/e4a064e29e9843663c2f368f20042b7f3dff9a3a/includes/file.php#L53)
 * ——————————–
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Ffile-attachment-error-4%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [8 months ago](https://wordpress.org/support/topic/file-attachment-error-4/#post-18678243)
 * OK. I understand your situation. Please tell the VIP team to open an issue on
   our [GitHub repository](https://github.com/rocklobster-in/contact-form-7).
 *  Thread Starter [pmarchand](https://wordpress.org/support/users/pmarchand/)
 * (@pmarchand)
 * [7 months, 3 weeks ago](https://wordpress.org/support/topic/file-attachment-error-4/#post-18684257)
 * [@takayukister](https://wordpress.org/support/users/takayukister/) This can be
   reproduced here by the way: [https://www-nationalfuel-com-preprod.go-vip.net/form-testing/](https://www-nationalfuel-com-preprod.go-vip.net/form-testing/)
 * VIP said they opened a ticket for this in the github repo.
 * I was wondering if a fix for this can be expected in the very near future or 
   not. Not sure what would need to be done to fix this, but just wanted to get 
   an idea of where things are at for this.
 * Thank you so much for looking into this in advance, it’s much appreciated.
 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [7 months, 3 weeks ago](https://wordpress.org/support/topic/file-attachment-error-4/#post-18684644)
 * Yes, the VIP team has opened an issue: [https://github.com/rocklobster-in/contact-form-7/issues/1711](https://github.com/rocklobster-in/contact-form-7/issues/1711)
 * We’ll continue the discussion there.
 * > I was wondering if a fix for this can be expected in the very near future or
   > not.
 * Maybe not. It is a complicated issue that will take a long time to fix.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘File Attachment Error’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * Last activity: [7 months, 3 weeks ago](https://wordpress.org/support/topic/file-attachment-error-4/#post-18684644)
 * Status: not resolved