首页 文章

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

提问于
浏览
0

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

PHP警告:mkdir():第64行/home/wppspeacepals/public_html/insertParentStudent.php中没有此类文件或目录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);
  }

2 回答

  • 0

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

    为了确保,您始终可以使用 mkdir() 的递归选项 - 它相当于在* nix mkdir 上使用 -p 选项 .

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

    消息很清楚 .

    1)请检查您是否已创建此目录

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

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

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

    mkdir /home/me/one/two
    

    如果您没有创建文件夹 one . 所以,你的代码应该像这样验证:

    $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;
    

相关问题