WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


mkdir($dir, 0777, true);
share|improve this question
thanks to all, i appreciated and voted up. – Jassi Oberoi Nov 26 '12 at 7:54
up vote 2 down vote accepted

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.

share|improve this answer
thanks toscho, its working. – Jassi Oberoi Nov 26 '12 at 7:26

You can use plugin_dir_path in your plugin to get current path in file system.

define( 'YOURPLUGIN_PATH', plugin_dir_path(__FILE__) );

code of the function itself

 * Gets the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in
 * @package WordPress
 * @subpackage Plugin
 * @since 2.8
 * @param string $file The filename of the plugin (__FILE__)
 * @return string the filesystem path of the directory that contains the plugin
    function plugin_dir_path( $file ) {
        return trailingslashit( dirname( $file ) );
share|improve this answer
my path is correct, there is no problem with plugins_url() but mkdir() not creating the folder – Jassi Oberoi Nov 25 '12 at 11:48
Do you understand that You tring to create directory on a file system with argument of URL? You need PATH of file which you use with plugin_dir_path help. defining a constant will make less code just typing $dir = YOURPLUGIN_PATH."/folder-name/; (in case if you had define your constant).. – qwerty qwerty Nov 25 '12 at 12:08

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.

define( 'STORING_DIRECTORY', WP_CONTENT_DIR . '/my_plugin_storing_directory/' );
$dir = STORING_DIRECTORY . '/folder-name/';

Maybe you want to use the upload directory to create your directories. Than you should use wp_upload_dir() to get the path.

$upload_dir = wp_upload_dir();
$dir = $upload_dir['basedir'] . '/folder-name/';
share|improve this answer
The upload directories are the only ones with guaranteed write access. You should not expect write access for WP_CONTENT_DIR. – toscho Nov 25 '12 at 21:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.