What functions of WP_Filesystem allow me to create a file with code-generated contents in a directory?

by coolpasta   Last Updated August 18, 2018 01:08 AM

I'm generating a very useful .dat file, but I read that file_put_contents if frowned upon and that WP_Filesystem should be used instead.

I see no methods to take dynamic input and create a file and then upload it to a directory of my choice at all.

What functions out of it should I look for?

My exact flow is: User clicks a button (the call is AJAX'd) and then 3 files are generated and put inside my directory. As of now, this is how the "save file" function looks like:

$contents = ob_get_clean();
\file_put_contents( THEME_DIR . '/dump/test.dat', $contents );

Related Questions

Downloadable content file structure

Updated September 21, 2017 13:08 PM

Standard location for plugin to save/cache files?

Updated August 23, 2015 18:03 PM

How to upload .tex files in wordpress?

Updated January 31, 2019 07:08 AM