PHP Include: Long Path Issue

2019-04-29 23:12发布

When I try to include a long file path the PHP include fails to load. A short include path works fine.

For example, the following will fail:

../../contents/2010-St-Louis-Rams-Tickets-Season-Package-Includes-Tickets-For-All-Regular-Season-Home-Games/inc/title.inc

Does anyone have any idea where the problem could be?

标签: php include
2条回答
太酷不给撩
2楼-- · 2019-04-30 00:08

Please check if your path (including drive name etc) exceeds 260 characters. Because that's the maximum directory length for Windows. Click here to see the reference.

The reference also states that there is the possibility to create extra-long path names by prepending the path name with "\?\". That should expand the maximum path length to 32767 characters. But I have no idea if this can be used within PHP.

查看更多
神经病院院长
3楼-- · 2019-04-30 00:15

I had the same issue with a symfony 1.x project when writing tests that looked something like this:

require_once __DIR__ . '/../../../../bootstrap/unit.php';
require_once __DIR__ . '/../../../../../../../MY/LONG/PATH.php'

The thing here is that those /../../.. take a lot of character space. In my case if those were not used it would work.

In symfony you can get the root of you project by calling sfConfig::get('sf_root_dir'), and thus I could change my code in the following way:

require_once __DIR__ . '/../../../../bootstrap/unit.php';
require_once sfConfig::get('sf_root_dir') . '/MY/LONG/PATH.php'

This works (in my case) perfectly.

Although here I use the root dir provided by the symfony framework, in your own project it's just a matter of defining the project's root dir somewhere and keep it accessible.

查看更多
登录 后发表回答