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);
Do not use the plugin directory to store new files.
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.You can use plugin_dir_path in your plugin to get current path in file system.
code of the function itself
In short: you need a PATH, not an URL
In long: Do not create directories in your plugin folder (see Toscho’s answer). Use the constant ´WP_CONTENT_DIR´ for the path instead of
plugins_url()
. This will create the directory within ´wp-content´ (on a standrad installation). Maybe you will define a sub-directory where you creates the directories.Maybe you want to use the upload directory to create your directories. Than you should use
wp_upload_dir()
to get the path.