Getting relative path from absolute path in PHP

Try this one: function getRelativePath($from, $to) { // some compatibility fixes for Windows paths $from = is_dir($from) ? rtrim($from, ‘\/’) . “https://stackoverflow.com/” : $from; $to = is_dir($to) ? rtrim($to, ‘\/’) . “https://stackoverflow.com/” : $to; $from = str_replace(‘\\’, “https://stackoverflow.com/”, $from); $to = str_replace(‘\\’, “https://stackoverflow.com/”, $to); $from = explode(“https://stackoverflow.com/”, $from); $to = explode(“https://stackoverflow.com/”, $to); $relPath = $to; … Read more

Relative import from parent directory

Edit: Relative import paths are not the way to go in Go. Lack of documentation shows something about popularity of relative paths, and I don’t see a reason for using them. Go’s recommended code organization works pretty well. Every package should have a unique import path and be imported everywhere using that same import path. … Read more

How to use a path relative to project root to H2 db-file configuration with Play Framework 2.4?

Ok, I did a little research and found this in the changelog (http://www.h2database.com/html/changelog.html): Implicit relative paths are disabled (system property “h2.implicitRelativePath”), so that the database URL jdbc:h2:test now needs to be written as jdbc:h2:./test. In H2 starting from version 1.4.177 Beta, implicit relative paths are not allowed anymore. Therefore, in your case the url should … Read more

Relative paths with fetch in Javascript

When you say fetch(‘data.json’) you are effectively requesting http://yourdomain.com/data.json since it is relative to the page you’re are making the request from. You should lead with forward slash, which will indicate that the path is relative to the domain root: fetch(‘/js/data.json’). Or fully qualify with your domain fetch(‘http://yourdomain.com/js/data.json’).

How to define a relative path in java

Try something like this String filePath = new File(“”).getAbsolutePath(); filePath.concat(“path to the property file”); So your new file points to the path where it is created, usually your project home folder. As @cmc said, String basePath = new File(“”).getAbsolutePath(); System.out.println(basePath); String path = new File(“src/main/resources/conf.properties”).getAbsolutePath(); System.out.println(path); Both give the same value.