Question

I have this fragment:

if(!$wp_filesystem->put_contents( $file_path, $file_content, FS_CHMOD_FILE )) {
    echo 'error during creating the file';
}

This code works properly, but instead of saving the file on the server I would like to display browser dialog box to save the file with this content on local disk.

Thanks in advance for any help.

Was it helpful?

Solution

... instead of saving the file on the server I would like to display browser dialog box to save the file with this content on local disk

The answer is that that is not what the Filesystem API does. You are trying to, or hoping to, use it incorrectly. It doesn't work that way. The Filesystem API saves to the server filesystem, not to the client disk. The server does not have that kind of control over the browser or the client machine, and for good reason.

What you will need to do is "ask" the browser to download-- something like this: https://stackoverflow.com/questions/8800714/how-to-show-the-save-dialog-using-html

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