s srinivas
s srinivas

Reputation: 121

Create Txt file from my custom wordpress plugin

I need to create text file from my custom plugin. it's like create text file and adding some content, then email the file to admin. i used fopen() function. It is giving me permission denied error.

fopen(/opt/lampp/htdocs/mysite/wp-content/plugins/custom-plugin/includes/Frontend/errors.txt): failed to open stream: Permission denied in /opt/lampp/htdocs/mysite/wp-content/plugins/custom-plugin/includes/Frontend/Frontend.php on line 130

my code is:

    $file = plugin_dir_path(__FILE__) . 'errors.txt';
    $open = fopen($file, "a");
    $write = fputs($open, $response);
    fclose($open);

Upvotes: 0

Views: 1372

Answers (1)

Mustafa sabir
Mustafa sabir

Reputation: 4360

Make sure the plugin directory has 777 permissions, wordpress default folder permissions are 775. You can change permission by running command if you have shell access:

sudo chmod 777 <path to you plugin dir>

Or if you have cpanel access, navigate using File Manager and right click the folder and select Change Permissions from the list.

Upvotes: 1

Related Questions