Title: fopen fails when folder is missing
Last modified: October 2, 2021

---

# fopen fails when folder is missing

 *  [vycwebmaster](https://wordpress.org/support/users/vycwebmaster/)
 * (@vycwebmaster)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/fopen-fails-when-folder-is-missing/)
 * $file = “/home/mywebsite/public_html/wp/wp-content/uploads/2021/10/somefile.txt”;
 * if (file_exists($file)) {
    $hFl = fopen($file,”a”); } else { $hFl = fopen($file,”
   c”); }
 * today I found a situation where folder 10 wasn’t created and so this logic fails
   to create somefile.txt
 * is there a switch to cause the folder to be generated at the same time as the
   file?

The topic ‘fopen fails when folder is missing’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wpforum.svg)
 * [WP Forum](https://wordpress.org/plugins/wpforum/)
 * [Support Threads](https://wordpress.org/support/plugin/wpforum/)
 * [Active Topics](https://wordpress.org/support/plugin/wpforum/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpforum/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpforum/reviews/)

## Tags

 * [fopen](https://wordpress.org/support/topic-tag/fopen/)

 * 0 replies
 * 1 participant
 * Last reply from: [vycwebmaster](https://wordpress.org/support/users/vycwebmaster/)
 * Last activity: [4 years, 8 months ago](https://wordpress.org/support/topic/fopen-fails-when-folder-is-missing/)
 * Status: not resolved