Question

In the script below, I need to convert the readfile to the WP_filesytem equivalent. However, I can't find same in Codex. Any help much appreciated.

This script saves the settings.ini file to the user's desktop/pc.

WP_Filesystem();
global $wp_filesystem;

$mySettingsFileLocation = WP_PLUGIN_DIR.'/my-settings/settings.ini';

if ( ! $wp_filesystem->put_contents( $mySettingsFileLocation, $mySettings, 0644) ) {
    return true;
}


// Define the path to file
 $file = WP_PLUGIN_DIR.'/my-settings/settings.ini';

 if(!$file)
 {
         // File doesn't exist, output error
         die('file not found');
 }
 else
 {
 // Set headers
 header("Cache-Control: public");
 header("Content-Description: File Transfer");
 header("Content-Disposition: attachment; filename=settings.ini");
 header("Content-Type: application/ini");
 header("Content-Transfer-Encoding: binary");

 // Read the file from disk
 readfile($file);
 }

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top