How to Create a Directory in a Plugin Folder?

I am creating a plugin in WordPress Version 3.4.2. When the administrator submits a form, a new folder is created inside my plugin directory and a file saved in this new folder.

But it gives me the following error:

error : The file has not been created 

$dir = plugins_url()."/folder-name/; 

The above code returns the following path:

http://localhost/website/wp-content/plugins/abc/folder-name

mkdir($dir, 0777, true);

3 Answers
3

Do not use the plugin directory to store new files.

  • During an update the plugin directory will be erased by WordPress. And all files in it too.
  • The plugin directory might be read-only in some setups (I do that always).

Use the regular uploads directory for that.

And 0777 is never a good idea. Write access for everyone is probably not what your users want.

Leave a Comment