I am writing a plugin that requires that I create a subfolder within the uploads directory.
Here's what I have tried thus far:
$uploads_dir = trailingslashit( wp_upload_dir( dirname( __FILE__) ) ) . '/evaluation-uploads';
wp_mkdir_p( $uploads_dir );
However when I check 'wp-content/uploads/' the subfolder has not been created.
Just use this modified version:
$uploads_dir = trailingslashit( wp_upload_dir()['basedir'] ) . 'evaluation-uploads';
wp_mkdir_p( $uploads_dir );
(Will only work on PHP 5.4+)
Corrections made:
dirname( __FILE__) as parameter to wp_upload_dirwp_upload_dir returns an array, so you need to access the path you needtrailingslashit will already remove and append a new trailing slash, so removed it from your stringAlso check file/dir user-permissions to ensure PHP can actually create a dir there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With