Rev 500 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
496 | daniel-mar | 1 | |
2 | |||
3 | How to get relative/absolute paths, e.g. when you are in a plugin? |
||
4 | |||
5 | |||
6 | |||
7 | +--------------------------------------------------------------------------------- |
||
8 | | Local path URL |
||
9 | --------------------------+--------------------------------------------------------------------------------- |
||
10 | | |
||
801 | daniel-mar | 11 | Get relative path | OIDplus::localpath(null, true) OIDplus::webpath(null, OIDplus::PATH_RELATIVE) |
12 | to base directory | Example: ../ Example: ../ |
||
496 | daniel-mar | 13 | | |
14 | | |
||
801 | daniel-mar | 15 | Get relative path | OIDplus::localpath('file.jpg', true) OIDplus::webpath('file.jpg', OIDplus::PATH_RELATIVE) |
16 | to any file/dir | Example: xyz/file.jpg Example: xyz/file.jpg |
||
496 | daniel-mar | 17 | | |
18 | | |
||
801 | daniel-mar | 19 | Get absolute path | OIDplus::localpath(null, false) OIDplus::webpath(null, OIDplus::PATH_ABSOLUTE) |
20 | to base directory | Example: /var/www/oidplus/ Example: https://www.example.com/oidplus/ |
||
496 | daniel-mar | 21 | | |
22 | | |
||
801 | daniel-mar | 23 | Get absolute path | OIDplus::localpath('file.jpg', true) OIDplus::webpath('file.jpg', OIDplus::PATH_ABSOLUTE) |
24 | to any file/dir | Example: /var/www/oidplus/xyz/file.jpg Example: https://www.example.com/oidplus/xyz/file.jpg |
||
496 | daniel-mar | 25 | | |
26 | --------------------------+--------------------------------------------------------------------------------- |
||
27 | |||
28 | |||
29 | These function ensure that directories end with a trailing path delimiter |
||
30 | |||
801 | daniel-mar | 31 | Note: Instead of OIDplus::PATH_ABSOLUTE you can use OIDplus::PATH_ABSOLUTE_CANONICAL |
32 | if you want to prefer the canonical system url, if set with the base config setting CANONICAL_SYSTEM_URL. |
||
500 | daniel-mar | 33 | |
34 | ---- |
||
35 | |||
36 | Here are some ways to test it: |
||
37 | |||
801 | daniel-mar | 38 | echo "Rel Webpath null: ";print_r(OIDplus::webpath(null,OIDplus::PATH_RELATIVE));echo "\n"; |
39 | echo "Rel Webpath non-existing: ";print_r(OIDplus::webpath('xxx',OIDplus::PATH_RELATIVE));echo "\n"; |
||
40 | echo "Rel Webpath existing: ";print_r(OIDplus::webpath('test',OIDplus::PATH_RELATIVE));echo "\n"; |
||
41 | echo "Rel Webpath self: ";print_r(OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE));echo "\n"; |
||
500 | daniel-mar | 42 | |
801 | daniel-mar | 43 | echo "Abs Webpath null: ";print_r(OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE));echo "\n"; |
44 | echo "Abs Webpath non-existing: ";print_r(OIDplus::webpath('xxx',OIDplus::PATH_ABSOLUTE));echo "\n"; |
||
45 | echo "Abs Webpath existing: ";print_r(OIDplus::webpath('test',OIDplus::PATH_ABSOLUTE));echo "\n"; |
||
46 | echo "Abs Webpath self: ";print_r(OIDplus::webpath(__DIR__,OIDplus::PATH_ABSOLUTE));echo "\n"; |
||
500 | daniel-mar | 47 | |
48 | echo "Rel localpath null: ";print_r(OIDplus::localpath(null,true));echo "\n"; |
||
49 | echo "Rel localpath non-existing: ";print_r(OIDplus::localpath('xxx',true));echo "\n"; |
||
50 | echo "Rel localpath existing: ";print_r(OIDplus::localpath('test',true));echo "\n"; |
||
51 | echo "Rel localpath self: ";print_r(OIDplus::localpath(__DIR__,true));echo "\n"; |
||
52 | |||
53 | echo "Abs localpath null: ";print_r(OIDplus::localpath(null,false));echo "\n"; |
||
54 | echo "Abs localpath non-existing: ";print_r(OIDplus::localpath('xxx',false));echo "\n"; |
||
55 | echo "Abs localpath existing: ";print_r(OIDplus::localpath('test',false));echo "\n"; |
||
56 | echo "Abs localpath self: ";print_r(OIDplus::localpath(__DIR__,false));echo "\n"; |