试图创建空的php文件,给出了失败打开流的权限拒绝wordpress。

问题描述 投票:0回答:0

我正试图在活动主题文件夹内编程创建一个自定义模板文件,并将其分配给帖子。我使用 fopen()file_put_contents() 仍然无法创建文件。

这是我的代码。

        if(isset($params["template_url"])){
            $basename = basename($params["template_url"]);
            if(!file_exists(get_stylesheet_directory()."/".$basename)){ // check if file not exist
            file_put_contents(get_stylesheet_directory()."/".$basename, unserialize($params["template_content"]));
            //$template_file = fopen(get_stylesheet_directory()."/".$basename, "a+");
            if(file_exists(get_stylesheet_directory()."/".$basename)){ // check if file created now
                //fwrite($template_file, unserialize($params["template_content"]));
                //fclose($template_file);
                update_post_meta($post_id,'_wp_page_template',$basename);
            }
            else{
                $error_message .= sprintf(__(' Error in creating template on %s.'),site_url());
            }
            } else {
                update_post_meta($post_id,'_wp_page_template',$basename);
            }
        }

谁能帮我解决这个问题?我一直在努力解决它从最后1天。

先谢谢你。

wordpress templates wordpress-theming fopen file-put-contents
© www.soinside.com 2019 - 2024. All rights reserved.