codingdir logo sitemap sitemap |
Home
PHP
C#
C++
ANDROID
JAVA
JAVASCRIPT
PYTHON

cant access files that have includes with relative URls


By : , Category : php

This sound like a work for __DIR__, you can check documentation here

The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(FILE). This directory name does not have a trailing slash unless it is the root directory. (Added in PHP 5.3.0.)

Otherwise you can still switch all your relative paths to absolute path and avoid any problem if some file are included in others.

As side note i would reccomend to not use php short tag <?...?>, I'd rather use long tags <?php....?>

ReLated :

I believe the simplest solution would be to add the following line to your header:

<base href="http://example.com/">

Then all of your relative paths will start from the root directory. The alternative is to update all of your relative paths corresponding to their location in the directory hierarchy. Something like:

$_SERVER['DOCUMENT_ROOT'] . '/dir1/dir2/page.html'

// or...

'../../page.html'

From the php.net site :

Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include will finally check in the calling script's own directory and the current working directory before failing. The include construct will emit a warning if it cannot find a file; this is different behavior from require, which will emit a fatal error

source

In case anyone runs into this annoying issue, the ClasspathUriResolver was the culprit, prepending a "/" on relative path includes. I switched it over to use a default Uri resolver (in org.apache.ws.commons.schema.resolver.DefaultURIResolver) and it runs fine without issue on Tomcat 8.

CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(
            schema);
collection.setUriResolver(new DefaultURIResolver());
collection.setInline(true);
return collection;

Set STATIC_URL when using a subdomain to serve your static files to the protocol relative url like so STATIC_URL = '//s.cdn.example.com/'.

Comments


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © codingdir.com All Rights Reserved .