PHP 警告: mkdir(): 没有这样的文件或目录 PHP WordPress.



下面的代码应该为国家/地区创建一个目录(两个字母的代码(,如果它不存在,则创建一个基于年龄组的目录,但是每当有人上传图像时,它都会作为损坏的图像出现,除非我预先创建目录,否则不会显示。我检查了错误日志,它给了我以下警告:

PHP 警告: mkdir((: 在/home/wppspeacepals/public_html/insertParentStudent.php 第 64 行中没有这样的文件或目录

PHP 警告: mkdir((: 在/home/wppspeacepals/public_html/insertParentStudent.php 第 70 行中没有这样的文件或目录

 $user_path = $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/wellness-
 pro/artis-images/".$get_Country->country."/".$age_group_label;
  if(!is_dir($user_path)){
    mkdir($user_path, 0777);
  }
  $user_id = $get_Country->prefix_char.$get_Country->registration_number;
  $user_path = $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/wellness-pro/artis-images/".$get_Country->country."/".$age_group_label."/".$user_id;
  if(!is_dir($user_path)){
    mkdir($user_path, 0777);
  }

除了最后一个元素(您的$age_group_label值(之外的整个路径是否已经存在? 即,在您尝试创建.../artist-images/atlantis/ancient之前,.../artist-images/atlantis/存在

为了确保,您始终可以对mkdir()使用递归选项 - 它等效于 在 *nix 上使用 -p 选项mkdir

mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = FALSE [, resource $context ]]] )

消息很明确。

1(请检查您是否创建了此目录

/wp-content/themes/wellness-pro/artist-images/

2(如果尚未创建$get_国家>国家/地区,您将收到此错误。尝试询问/wp-content/themes/wellness-pro/artis-images/".$get_Country->country 是否存在is_dir((。如果是,则使用 $age_group_label 创建最后一个文件夹。如果没有,您将必须首先创建国家/地区文件夹,然后创建年龄组文件夹。

基本上你不能通过做创建文件夹

mkdir /home/me/one/two

如果您没有创建文件夹 1。因此,您的代码应像这样验证这一点:

$user_path_country = $_SERVER['DOCUMENT_ROOT']."/wp-
content/themes/wellness-
pro/artis-images/".$get_Country->country;
$user_path_age = $user_path_country."/".$age_group_label;
if (!is_dir($user_path_country)):
mkdir($user_path_country, 0777);
else:
mkdir($user_path_age, 0777);
endif;

最新更新