Creating a file from a wordpress plugin

Mar 13, 2012   //   by phpfreelancer.biz   //   Blog, Wordpress Plugin Tutorial  //  No Comments

I am creating a wordpress plugin that needs to be able save a file. What is the best way to do this without worrying about file permissions. (i.e Is there a directory that is considered safe to write to?)

If you can upload images to your blog, then wp-content/uploads should be writable.But file permissions are always something to worry a little about when you’re deploying to a new server.

Normally you can create a directory with mkdir(), permissions to chmod(777) so you can delete this directory from ftp without a root user and this dir will bee fully writable via php. And also chmod you files with 777, otherwise you can’t delete without root permissions.

<?php 
mkdir(WP_PLUGIN_DIR . '/my_plugin/my_dir', 0777, TRUE);
?>

by using the above we can set the permission to the directory.

Leave a comment

Share This Post

RSS Wordpress News