Hello,
If you have the whole server path for a file is there a canonical way to get
the path from document root for that file so that you can present the file
ina browser or for download? Check $_SERVER['document_root'] and parse the
path?
My thought is that given OS diversity and individual server differences (eg
www vs public_html vs htdocs) that there may be no one-size-fits-all
solution but I thought I would throw this out there any way.
Thanks for any advice,
jg 8 2964
Hi
I don't even know, if I understood this, but here's my solution:
str_replace the string in the file-path that's equal to the doc-root by ""
or by "/" (or by the server-name; well this requires a second look at the
problem)... done
$file_name =
str_replace(dirname($_SERVER["DOCUMENT_ROOT"])."/","",dirname($file_name)."/
").basename($file_name);
// the over-use of dirname() is just to prevent OS-specific
// problems with the file-system
guess this only works, if the file is in a folder that's reachable from
outside the server (otherwise it would be sensless).
On Fri, 17 Sep 2004 11:57:39 -0500, "jerrygarciuh"
<de*****@no.spam.nolaflash.com> wrote: Hello,
If you have the whole server path for a file is there a canonical way to get the path from document root for that file so that you can present the file ina browser or for download? Check $_SERVER['document_root'] and parse the path?
My thought is that given OS diversity and individual server differences (eg www vs public_html vs htdocs) that there may be no one-size-fits-all solution but I thought I would throw this out there any way.
Thanks for any advice,
jg
If I understand your question correctly, you could use something like:
$path = dirname($_SERVER['PHP_SELF']);
If the URI is 'foo.com/bar/baz/page.php', $path will be '/bar/baz'.
HTH =)
Regards,
Ian
--
Ian.H
digiServ Network
London, UK http://digiserv.net/
Ian,
Thanks for the reply!
What I am trying to do is take data that looks like these:
$fullPath = '/home/sumsite/public_html/facilities/vDocs/1/Clown.jpg';
$fullPath = '/home/sumsite/public_html/facilities/Dog.jpg';
and parse them uniformly into
$webPath = /facilities/vDocs/1/Clown.jpg';
$webPath = /facilities/Dog.jpg';
So they can be accessed by a browser. PHP_SELF in these case won't relate
to the dir in question. Maybe I can use chdir to my advantage here...
Thanks for looking,
jg
"Ian.H" <ia*@WINDOZEdigiserv.net> wrote in message
news:mt********************************@4ax.com... On Fri, 17 Sep 2004 11:57:39 -0500, "jerrygarciuh" <de*****@no.spam.nolaflash.com> wrote:
Hello,
If you have the whole server path for a file is there a canonical way to
getthe path from document root for that file so that you can present the
fileina browser or for download? Check $_SERVER['document_root'] and parse
thepath?
My thought is that given OS diversity and individual server differences
(egwww vs public_html vs htdocs) that there may be no one-size-fits-all solution but I thought I would throw this out there any way.
Thanks for any advice,
jg
If I understand your question correctly, you could use something like:
$path = dirname($_SERVER['PHP_SELF']);
If the URI is 'foo.com/bar/baz/page.php', $path will be '/bar/baz'.
HTH =) Regards,
Ian
-- Ian.H digiServ Network London, UK http://digiserv.net/
CR,
Thanks for the reply! Your code takes
$fullPath = '/home/sumsite/public_html/facilities/vDocs/1/Clown.jpg';
and returns "/";
I need it to return "/facilities/vDocs/1/Clown.jpg"; so a browser can get
the file.
Any advice?
TIA!
jg
"Christopher-Robin" <Ch***************@gmx.de> wrote in message
news:ci*************@news.t-online.com... Hi
I don't even know, if I understood this, but here's my solution:
str_replace the string in the file-path that's equal to the doc-root by "" or by "/" (or by the server-name; well this requires a second look at the problem)... done
$file_name =
str_replace(dirname($_SERVER["DOCUMENT_ROOT"])."/","",dirname($file_name)."/ ").basename($file_name);
// the over-use of dirname() is just to prevent OS-specific // problems with the file-system
guess this only works, if the file is in a folder that's reachable from outside the server (otherwise it would be sensless).
Sorry, was testing carelessly.
This test:
$file_name = '/home/sumsite/public_html/facilities/vDocs/1/Clown.jpg';
echo $_SERVER["DOCUMENT_ROOT"] . '<p>';
echo $file_name =
str_replace(dirname($_SERVER["DOCUMENT_ROOT"])."/","",dirname($file_name)."/
").basename($file_name);
Prints:
/usr/local/apache/htdocs
/home/sumsite/public_html/facilities/vDocs/1/Clown.jpg
Your code looks good, I just have to figure out the doc root issue.
Thanks,
jg
"jerrygarciuh" <de*****@no.spam.nolaflash.com> wrote in message
news:_BG2d.25404$ni.8768@okepread01... CR,
Thanks for the reply! Your code takes
$fullPath = '/home/sumsite/public_html/facilities/vDocs/1/Clown.jpg';
and returns "/";
I need it to return "/facilities/vDocs/1/Clown.jpg"; so a browser can get the file.
Any advice?
TIA!
jg
"Christopher-Robin" <Ch***************@gmx.de> wrote in message news:ci*************@news.t-online.com... Hi
I don't even know, if I understood this, but here's my solution:
str_replace the string in the file-path that's equal to the doc-root by
"" or by "/" (or by the server-name; well this requires a second look at
the problem)... done
$file_name =
str_replace(dirname($_SERVER["DOCUMENT_ROOT"])."/","",dirname($file_name)."/ ").basename($file_name);
// the over-use of dirname() is just to prevent OS-specific // problems with the file-system
guess this only works, if the file is in a folder that's reachable from outside the server (otherwise it would be sensless).
On Fri, 17 Sep 2004 11:57:39 -0500, "jerrygarciuh"
<de*****@no.spam.nolaflash.com> wrote: If you have the whole server path for a file is there a canonical way to get the path from document root for that file so that you can present the file ina browser or for download? Check $_SERVER['document_root'] and parse the path?
My thought is that given OS diversity and individual server differences (eg www vs public_html vs htdocs) that there may be no one-size-fits-all solution but I thought I would throw this out there any way.
There may be multiple URLs that map to the same filesystem file - do you want
all of them, or just one? A method to do this properly would be a bit of
challenge as it would require some understanding of the webserver's
configuration (whichever webserver you're using).
If you're just dealing with the base case of one document root covering all
accessible files, then the Christopher-Robin's post looks like the way to go.
--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Well,
This is the best I have been able to do. FAR from a global solution but
looks like it would work a lot of the time:
$path = '/home/someGuy/public_html/facilities/vDocs/1/Clown.jpg';
$pathAry = preg_split('/public_html|www/', $path);
echo $pathAry[1];
Thanks for the replies!
jg
"jerrygarciuh" <de*****@no.spam.nolaflash.com> wrote in message
news:eIE2d.25393$ni.20060@okepread01... Hello,
If you have the whole server path for a file is there a canonical way to
get the path from document root for that file so that you can present the file ina browser or for download? Check $_SERVER['document_root'] and parse
the path?
My thought is that given OS diversity and individual server differences
(eg www vs public_html vs htdocs) that there may be no one-size-fits-all solution but I thought I would throw this out there any way.
Thanks for any advice,
jg
try $_SERVER["SCRIPT_FILENAME"] or $_SERVER["PATH_TRANSLATED"] instead of
$_SERVER["DOCUMENT_ROOT"]
well, im not sure (its already 4am here)
there are many pre-defined variables in $_SERVER; just do an echo-loop to
check which is suitable
foreach($_SERVER as $i => $j)
echo "$i => $j<br>\n"; This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: gwen |
last post by:
Hi, I have a code to copy/move folders to a specified folder on the
root drive - ie c:\stuff However, I also have the folder "stuff" on
the root of other partitions as well - ie d:\stuff,...
|
by: Ben Wan |
last post by:
Can anyone please tell me what is canonical path? and why does it need to throws IOexception?
how come getAbsolutePath() doesn't return "c:\folder\folder" but getCanonicalPath() does?
things I...
|
by: |
last post by:
Is it possible to include my remote web server path eg: m:/html/root/site1
| m:/html/root/site2 etc
....in virtual includes....
Thus eliminating the need to create duplicate INC files in each...
|
by: KarimL |
last post by:
Thanks for your advices...
but i need to get the Image height because i dynamically resize the height
of my webcontrol based on the image height.
More i just have the url (relative parth) to the...
|
by: Praveen |
last post by:
Hi All,
I have made a webservice in C# and it works fine in my machine. I ran into a
crazy problem when I wanted to deploy it in windows 2003 server. I have run
"aspnet_regiis.exe -i" to make...
|
by: ruju00 |
last post by:
I am getting an error in Login() method of the following class
FtpConnection
public class FtpConnection
{
public class FtpException : Exception
{
public FtpException(string message) :...
|
by: EP |
last post by:
This inquiry may either turn out to be about the suitability of the
SHA-1 (160 bit digest) for file identification, the sha function in
Python ... or about some error in my script. Any insight...
|
by: Hitesh |
last post by:
Hi,
I have a small script here that goes to inside dir and sorts the file
by create date. I can return the create date but I don't know how to
find the name of that file...
I need file that is...
|
by: lawpoop |
last post by:
Hello all -
I have a two part question.
First of all, I have a website under /home/user/www/. The index.php
and all the other website pages are under /home/user/www/. For
functions that are...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |