search
HomeBackend DevelopmentPHP TutorialPHP不能识别“./”和“/”相对路径,这是哪里配置不对?

PHP版本是5.3.29,这个程序之前在别的服务器上是正常的,现在移到新的服务器上,凡事有相对路径“./”和“../”的,都不能识别,提示类似下面的:
Warning: include_once(../../../../../Lang/zh-cn/calendar.php): failed to open stream: No such file or directory in D:\wwwroot\xingxing\web\admin\Tpl\default\Common\js\calendar\calendar.php on line 9

Warning: include_once(): Failed opening '../../../../../Lang/zh-cn/calendar.php' for inclusion (include_path='.;C:\php\pear') in D:\wwwroot\xingxing\web\admin\Tpl\default\Common\js\calendar\calendar.php on line 9

Notice: Undefined variable: _LANG in D:\wwwroot\xingxing\web\admin\Tpl\default\Common\js\calendar\calendar.php on line 11

Warning: Invalid argument supplied for foreach() in D:\wwwroot\xingxing\web\admin\Tpl\default\Common\js\calendar\calendar.php on line 11

文件路径是没有问题的,因为在别的服务器上都是正常的。如果把“./”改成dirname(__FILE__),程序也是可以正常运行的。但就是不能识别相对路径。请问这种情况是PHP哪里配置不对的吗,还是IIS配置不对。

因为程序是别人做的,而且很多地方都使用了相对路径,所以很难一个个文件去把路径都改成绝对路径。

下面网盘链接是phpinfo()的代码:
https://pan.baidu.com/s/1qWZHaKs


回复讨论(解决方案)

<?phpecho getcwd();echo dirname(__FILE__);?>

上面的代码输出的是:
C:\php
D:\wwwroot\xingxing\web
补充说明:在网站根目录下输出echo getcwd();显示出来的是:C:\php,而echo dirname(__FILE__);打印出来的是:D:\wwwroot\xingxing\web,而D:\wwwroot\xingxing\web

猜你就是用的 IIS 
你需要在管理器的网站属性选项卡中 勾选 启用父路径

猜你就是用的 IIS 
你需要在管理器的网站属性选项卡中 勾选 启用父路径



谢谢版主,以前IIS6的时候我记得有这个设置的,但是现在用的是IIS7,没找到这个选项,网上找到的也都是ASP设置父路径的方法
我是用的IIS7,win2008的,对服务器配置不懂,具体在哪里设置呢

http://www.softbar.com/blog/post/187.html

自己找找看吧,我几年前弄过。现在也记不清了

http://www.softbar.com/blog/post/187.html
自己找找看吧,我几年前弄过。现在也记不清了



这个是ASP的设置呢,PHP的没见有,还是IIS7就没有这玩意了

我猜你是权限不足的原因  比如 你PHP 网站绑定的是wwww/csdn  你来宾权限只到csdn 到不了wwww从而导致的
你试试给wwww 权限放大

你做了就知道!

问题解决了,你们两位说的问题都不是。我在网上下载一个同版本的PHP,然后把里面的php.ini替换了服务器上的php.ini就可以了。也不知道是php.ini里面哪里设置不对的。这个是阿里云的主机,PHP不知道是原来自带的还是后面装上的,反正因为这个设置就有各种各样的问题,连getcwd();都获取不到当前目录,获取到的是c:\php目录

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools