我在使用Bluehost进行WordPress安装时遇到了一些状况,因为没有上传文件夹wp-content/uploads
,个人WordPress主题遇到了错误。 php
显然,尽管HostGator能够,Bluehost cPanel WordPress安装程序不会建立此文件夹。 session
所以,我须要向主题添加代码,以检查文件夹并以其余方式建立该文件夹。 app
这是丢失的一块。 您须要像这样在mkdir调用中将“递归”标志做为第三个参数(布尔值true)传递: wordpress
mkdir('path/to/directory', 0755, true);
if (!is_dir('path_directory')) { @mkdir('path_directory'); }
对于登陆站点,我须要相同的内容。 我须要用两个变量建立一个目录。 $ directory是我要使用用户许可证号建立另外一个子文件夹的主文件夹。 函数
include_once("../include/session.php"); $lnum = $session->lnum; //Users license number from sessions $directory = uploaded_labels; // Name of directory that folder is being created in if (!file_exists($directory."/".$lnum)) { mkdir($directory."/".$lnum, 0777, true); }
在WordPress中,还有一个很是方便的函数wp_mkdir_p ,它将以递归方式建立目录结构。 spa
资料来源:- .net
function wp_mkdir_p( $target ) { $wrapper = null; // strip the protocol if( wp_is_stream( $target ) ) { list( $wrapper, $target ) = explode( '://', $target, 2 ); } // from php.net/mkdir user contributed notes $target = str_replace( '//', '/', $target ); // put the wrapper back on the target if( $wrapper !== null ) { $target = $wrapper . '://' . $target; } // safe mode fails with a trailing slash under certain PHP versions. $target = rtrim($target, '/'); // Use rtrim() instead of untrailingslashit to avoid formatting.php dependency. if ( empty($target) ) $target = '/'; if ( file_exists( $target ) ) return @is_dir( $target ); // We need to find the permissions of the parent folder that exists and inherit that. $target_parent = dirname( $target ); while ( '.' != $target_parent && ! is_dir( $target_parent ) ) { $target_parent = dirname( $target_parent ); } // Get the permission bits. if ( $stat = @stat( $target_parent ) ) { $dir_perms = $stat['mode'] & 0007777; } else { $dir_perms = 0777; } if ( @mkdir( $target, $dir_perms, true ) ) { // If a umask is set that modifies $dir_perms, we'll have to re-set the $dir_perms correctly with chmod() if ( $dir_perms != ( $dir_perms & ~umask() ) ) { $folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) ); for ( $i = 1; $i <= count( $folder_parts ); $i++ ) { @chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms ); } } return true; } return false; }
尝试这个: code
if (!file_exists('path/to/directory')) { mkdir('path/to/directory', 0777, true); }
请注意, 0777
已是目录的默认模式,而且仍可能被当前的umask修改。 orm