relative-path

Inconsistency when switching between development to live server?

ⅰ亾dé卋堺 提交于 2019-11-26 14:09:55
问题 I always have trouble when moving a site that I've developed in localhost into my hosting server with the .htaccess file. Specifically with relative paths to the files. It's not hard to fix, but it's quite bothering. For example: Whereas ErrorDocument 404 /foo/404.php works in the hosting, for it to work in localhost I have to specify ErrorDocument 404 /projectroot/foo/404.php . When using mod_rewrite, RewriteRule ^example/$ example.php [L,NC] works in localhost, but for it to work in the

Ultimate answer to relative python imports

六月ゝ 毕业季﹏ 提交于 2019-11-26 14:08:36
问题 I know that there are lots of questions about the same import issues in Python but it seems that nobody managed to provide a clear example of correct usage. Let's say that we have a package mypackage with two modules foo and bar . Inside foo we need to be able to access bar . Because we are still developing it, mypackage is not in sys.path . We want to be able to: import mypackage.foo run foo.py as a script and execute the sample usage or tests from the __main__ section. use Python 2.5 How do

Accessing JAR resources

僤鯓⒐⒋嵵緔 提交于 2019-11-26 12:46:40
问题 I have a jar file with resources (mainly configuration for caches, logging, etc) that I want to distribute. I\'m having a problem with the relative paths for those resources, so I did what I\'ve found in another stackoverflow question, which said that this was a valid way: ClassInTheSamePackageOfTheResource.class.getResourceAsStream(\'resource.xml\'); Sadly this does not work. Any ideas? Thanks! PS: Obviously I cannot use absolute paths, and I\'d like to avoid environment variables if

Getting relative path from absolute path in PHP

瘦欲@ 提交于 2019-11-26 12:38:18
问题 I noticed some similar questions about this problem when I typed the title, but they seem not be in PHP. So what\'s the solution to it with a PHP function? To be specified. $a=\"/home/apache/a/a.php\"; $b=\"/home/root/b/b.php\"; $relpath = getRelativePath($a,$b); //needed function,should return \'../../root/b/b.php\' Any good ideas? Thanks. 回答1: Try this one: function getRelativePath($from, $to) { // some compatibility fixes for Windows paths $from = is_dir($from) ? rtrim($from, '\/') . '/' :

How to find the working folder of a servlet based application in order to load resources

China☆狼群 提交于 2019-11-26 12:32:22
I write a Java servlet that I want to install on many instances of Tomcat on different servers. The servlet uses some static files that are packed with the war file under WEB-INF. This is the directory structure in a typical installation: - tomcat -- webapps --- myapp ---- index.html ---- WEB-INF ----- web.xml ----- classes ------ src ------- ..... ----- MY_STATIC_FOLDER ------ file1 ------ file2 ------ file3 How can I know the absolute path of MY_STATIC_FOLDER, so that I can read the static files? I cannot rely on the "current folder" (what I get in a new File(".")) because it depends on

How to import a Python module from a sibling folder?

痴心易碎 提交于 2019-11-26 12:29:21
问题 I have gone through many Python relative import questions but I can\'t understand the issue/get it to work. My directory structure is: Driver.py A/ Account.py __init__.py B/ Test.py __init__.py Driver.py from B import Test Account.py class Account: def __init__(self): self.money = 0 Test.py from ..A import Account When I try to run: python Driver.py I get the error Traceback (most recent call last): from B import Test File \"B/Test.py\", line 1, in <module> from ..A import Account ValueError:

Importing from a relative path in Python

风流意气都作罢 提交于 2019-11-26 12:06:53
问题 I have a folder for my client code, a folder for my server code, and a folder for code that is shared between them Proj/ Client/ Client.py Server/ Server.py Common/ __init__.py Common.py How do I import Common.py from Server.py and Client.py? 回答1: EDIT Nov 2014 (3 years later): Python 2.6 and 3.x supports proper relative imports, where you can avoid doing anything hacky. With this method, you know you are getting a relative import rather than an absolute import. The '..' means, go to the

Transform relative path into absolute URL using PHP

怎甘沉沦 提交于 2019-11-26 11:52:15
How to, using php, transform relative path to absolute URL? jordanstephens function rel2abs($rel, $base) { /* return if already absolute URL */ if (parse_url($rel, PHP_URL_SCHEME) != '') return $rel; /* queries and anchors */ if ($rel[0]=='#' || $rel[0]=='?') return $base.$rel; /* parse base URL and convert to local variables: $scheme, $host, $path */ extract(parse_url($base)); /* remove non-directory element from path */ $path = preg_replace('#/[^/]*$#', '', $path); /* destroy path if relative url points to root */ if ($rel[0] == '/') $path = ''; /* dirty absolute URL */ $abs = "$host$path/

MVC Bundling and CSS relative URLs

蹲街弑〆低调 提交于 2019-11-26 10:33:17
问题 MVC\'s bundling is returning the wrong URL in CSS images when using CssRewriteUrlTransform: I have an intranet application whose URL is, for example: http://usid01-srv002/MyApplication . It\'s in IIS\'s \"Default Web Site\". Which has the following in BundleConfig.cs : bundles.Add(new StyleBundle(\"~/bundles/jcss\") .Include(\"~/Scripts/JQueryUI/css/*.css\", new CssRewriteUrlTransform()) ); The bundling system is generating the wrong URL for any images referenced in those CSS files, yielding

How do relative file paths work in Eclipse?

跟風遠走 提交于 2019-11-26 10:30:47
问题 So my 2009 new years resolution is to learn Java. I recently acquired \"Java for Dummies\" and have been following along with the demo code in the book by re-writing it using Eclipse. Anyway, every example in the book that uses a relative path does not seem to read the .txt file it\'s supposed to read from. Here is the sample code: import java.util.Scanner; import java.io.File; import java.io.IOException; import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.GridLayout; class