Absolute path back to web-relative path
Perhaps this might work:
String RelativePath = AbsolutePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty);
I'm using c# but could be adapted to vb.
absolute path to relative path outside the ASP.NET app folder
Basically, you've got three ways:
- Use a file system solution - Create a hardlink in your application directory that points to C:\Image. Everything should work just fine.
- Add a new virtual directory ("Images") in your application directory, that points to C:\Image.
- Create your own HttpModule / HttpHandler to server the files from your C:\Image directory.
I can write more about any of these solutions if you'd like.
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, '\/') . '/' : $from;
$to = is_dir($to) ? rtrim($to, '\/') . '/' : $to;
$from = str_replace('\\', '/', $from);
$to = str_replace('\\', '/', $to);
$from = explode('/', $from);
$to = explode('/', $to);
$relPath = $to;
foreach($from as $depth => $dir) {
// find first non-matching dir
if($dir === $to[$depth]) {
// ignore this directory
array_shift($relPath);
} else {
// get number of remaining dirs to $from
$remaining = count($from) - $depth;
if($remaining > 1) {
// add traversals up to first matching dir
$padLength = (count($relPath) + $remaining - 1) * -1;
$relPath = array_pad($relPath, $padLength, '..');
break;
} else {
$relPath[0] = './' . $relPath[0];
}
}
}
return implode('/', $relPath);
}
This will give
$a="/home/a.php";
$b="/home/root/b/b.php";
echo getRelativePath($a,$b), PHP_EOL; // ./root/b/b.php
and
$a="/home/apache/a/a.php";
$b="/home/root/b/b.php";
echo getRelativePath($a,$b), PHP_EOL; // ../../root/b/b.php
and
$a="/home/root/a/a.php";
$b="/home/apache/htdocs/b/en/b.php";
echo getRelativePath($a,$b), PHP_EOL; // ../../apache/htdocs/b/en/b.php
and
$a="/home/apache/htdocs/b/en/b.php";
$b="/home/root/a/a.php";
echo getRelativePath($a,$b), PHP_EOL; // ../../../../root/a/a.php
HTML relative paths to my JavaScript files aren't working
I think the issue is that you cannot define the relative path above the document root of the site, which would be the html folder. Depending on the webserver, this may be forbiden.
Ideally you would create a scripts folder inside the html folder and point to it that way.
/var/www/html/index.html
/var/html/scripts/file.js
Difference between Relative path and absolute path in javascript
What is the difference between Relative path and absolute path?
One has to be calculated with respect to another URI. The other does not.
Is there any performance issues occures for using these paths?
Nothing significant.
We will get any secure for the sites ?
No
Is there any way to converting absolute path to relative
In really simplified terms: Working from left to right, try to match the scheme, hostname, then path segments with the URI you are trying to be relative to. Stop when you have a match.
Related Topics
Very Slow Compile Times on Visual Studio 2005
Why Are C# 4 Optional Parameters Defined on Interface Not Enforced on Implementing Class
Dependency Injection in Unit of Work Pattern Using Repositories
What's the New C# Await Feature Do
Export Datatable to Excel File
Restrict Access to a Specific Controller by Ip Address in ASP.NET MVC Beta
What Does the Word "Literal" Mean
How to View Msil/Cil Generated by C# Compiler? Why Is It Called Assembly
Good Aes Initialization Vector Practice
What Does |= (Single Pipe Equal) and &=(Single Ampersand Equal) Mean
How to Read Values from the Querystring with ASP.NET Core
Get Property Name and Type Using Lambda Expression
Generic Method Multiple (Or) Type Constraint