Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

File (x) is not within the allowed path

Started by Muut Archive 10 years ago · 11 replies · 968 views
10 years ago

I am using the woo theme. I runs smoothly locally. When I upload to a production server I get this message for images directly linked from the content:

Whoops \ Exception \ ErrorException (E_WARNING)
file_exists(): open_basedir restriction in effect. File(/customers/f/6/haraluna.no/httpd.www/user/pages/images/web-hoved- bilde.png) is not within the allowed path(s): (/customers/f/6/0/haraluna.no/httpd.www:/customers/f/6/0/haraluna.no/h ttpd.private:/customers/f/6/0/haraluna.no/tmp:/customers/haraluna.no/haraluna.no:/var/www/diagnostics:/usr/share/php)

The '0' have been removed from the path so the path is not valid. Seems to be a problem with the URL conversion.

10 years ago

Thank you for your quick reply. I think the open_basedir setting is ok. The file I am referring lays within the basedir, see path above. The problem is the getgrav code seems to be removing a zero in the path. Accessing images through frontmatter/twig template works, but accessing directly from content like this causes the error.

10 years ago

One workaround is to address the image with its full and absolute www url, but that means I need to update the code when changing from local to production environments, and using a relative path is always preferable of course.

10 years ago

Regarding the production server's open_basedir settings: I don't think I can control that.

10 years ago

Are you sure it's not some rewrite rule on your end? Grav is not doing any specific rewrites of URLs unless you set something up in the your webserver or in the rewrite options of site.yaml

10 years ago

I am using the default .htaccess file provided by the theme, keeping all those rewrite rules, only changing the "RewriteBase" line to point to the actual sub directory. I have no rewrite options in site.yaml. Anyway, the problem is in path as far as I can tell.

10 years ago

I replaced the image line to a standard html src img line and then it works. So the issue is no longer stopping me. Thanks for your help.

10 years ago

I was hit hard by this issue again today. I made a workaround by changing Grav/Util:normalizePath to do nothing. I cannot read php code so I am not able to explain exactly what goes wrong. Cannot see how this function can remove a zero from the path.

10 years ago

Please tell me if you think this workaround has any adverse side effects. My pages seems to work as they should. I can post an issue if you like.

10 years ago

Hi @haralduna, currently I have no Grav install to test, but in my eyes you definitely found a bug in the function you mentioned above. Please create an issue. The reason is that at line 333 empty('0') returns true, which is obviously wrong. A fix might be to change L333 with

PHP
if (($segment == '.') || strlen($segment) == 0) {
   ...
}

Can you try that and attach the fix to your issue?

10 years ago

Can confirm that the fix works (tried locally and on production server). Will create an issue later today.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1330 9 years ago
Archive · by Muut Archive, 9 years ago
2 922 9 years ago
Archive · by Muut Archive, 9 years ago
2 4052 9 years ago
Archive · by Muut Archive, 9 years ago
1 2930 9 years ago
Archive · by Muut Archive, 9 years ago
3 1109 9 years ago