使用require_once进行升级目录不工作 [英] Using require_once for up directory not working

查看:96
本文介绍了使用require_once进行升级目录不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这样的require_once

I am using require_once like this

require_once('../mycode.php')

我正在开发一个wordpress插件。我的插件文件夹是yves-slider,我有一个名为yves-slider.php的文件和一个名为admin的文件夹。里面的管理员文件夹我有一个名为admin.php的文件。我想在我的admin.php中要求文件yves-slider.php,该文件位于一级目录中。当我尝试使用

I am developing a wordpress plugin. My plugin folder is yves-slider where I have a file called yves-slider.php and a folder called admin. Inside admin folder I have a file called admin.php. I want to require file yves-slider.php in my admin.php which is located up one level directory. When I try to use

require_once('../yves-slider.php')

它给我以下错误


警告:require_once(../ yves-slider.php):无法打开流:否
这样的文件或
中的目录C:\xampp\htdocs\wordpress\wp-content\插件\yves-slider \yves-slider-admin \yves-slider-admin.php
在第4行

Warning: require_once(../yves-slider.php): failed to open stream: No such file or directory in C:\xampp\htdocs\wordpress\wp-content\plugins\yves-slider\yves-slider-admin\yves-slider-admin.php on line 4

致命错误:require_once() :
C:\xampp\htdocs中的
'../yves-slider.php'(include_path ='; C:\xampp\php\PEAR')失败打开第4行的\wordpress\wp-content\plugins\yves-slider\yves-slider-admin\yves-slider-admin.php

Fatal error: require_once(): Failed opening required '../yves-slider.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\wordpress\wp-content\plugins\yves-slider\yves-slider-admin\yves-slider-admin.php on line 4

我做错了吗?我正在使用XAMPP 3.1,我想这是最好的方式。

Am I doing wrong? I am using XAMPP 3.1, I guess that's the best way to do it.

推荐答案

路径文件位于:

require_once __DIR__ . '/../yves-slider.php';

可能发生的一件事是,PHP所看到的当前路径是不是你认为的路径。如果你对它是什么(当前的路径)好奇,你可以做 echo getcwd() ;

What probably is happening is that the current path PHP looks in is not the path you think it is. If you are curious about what it is (the current path) you could do echo getcwd();.

这篇关于使用require_once进行升级目录不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆