inarius Posted March 9, 2007 Share Posted March 9, 2007 What's the easiest way to convert a local URL, such as $_SERVER['PHP_SELF'], to a local file path? I don't just want the path to the current file or directory. I wanted to find a (hopefully simple) function that would take any url on my server and give me the local file path it corresponds to. Thanks! Quote Link to comment Share on other sites More sharing options...
chronister Posted March 9, 2007 Share Posted March 9, 2007 $_SERVER['DOCUMENT_ROOT']; returns something like C:/Program Files/xampp/htdocs/website on a windows system or /path/to/your/files/ on a linux system Is this what your looking for? Quote Link to comment Share on other sites More sharing options...
Glyde Posted March 9, 2007 Share Posted March 9, 2007 function get_current_file() { return $_SERVER['DOCUMENT_ROOT'] . $_SERVER['PHP_SELF']; } Other than that I can't think of any purpose for trying to find that information out. I guess you could do: function get_local($url) { $urlParts = parse_url($url); return $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $urlParts['path']; } Completely untested, so I'm not entirely sure how it'll work. Quote Link to comment Share on other sites More sharing options...
inarius Posted March 9, 2007 Author Share Posted March 9, 2007 I have actually tested something like this. I am using shared webspace provided by my school, and when I tested the output of $_SERVER['DOCUMENT_ROOT'], I got something I didn't expect. $_SERVER['DOCUMENT_ROOT'] returns "/usrweb2/netsite-docs" __FILE__ returns "/d3/home/student/amb93/public_html/index.php" All of this maps to a web address like http://www.hostname.com/~amb93/index.html So, I would like a function that can take the URL http://www.hostname.com/~amb93/classwork/ and return "/d3/home/student/amb93/public_html/classwork/" Quote Link to comment Share on other sites More sharing options...
inarius Posted March 9, 2007 Author Share Posted March 9, 2007 *bump* Please refer to my clarification on my question above. The solutions posted will not work for me... Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 9, 2007 Share Posted March 9, 2007 are you using a shared hosting package? if so i think you wont get the current folders with any php built in function's just for now your have to use the directory nam e you no ok. unless but a big but the hosting company change there whole configreaction for you! Quote Link to comment Share on other sites More sharing options...
inarius Posted March 9, 2007 Author Share Posted March 9, 2007 Yes, shared hosting provided by my school. No, I definitely can't change any configuration. I don't understand why the DOCUMENT_ROOT is so different from what I expect, but is there really no way to accomplish what I am trying to do? Quote Link to comment Share on other sites More sharing options...
Glyde Posted March 9, 2007 Share Posted March 9, 2007 Document_root is the document root to your school's main web page (most likely). If your URL is something like http://yourschool.com/~yourusername, it'll load files from some other drive on the computer, while the document_root still remains the root path for http://yourschool.com. Example, http://yourschool.com may load from /usrweb2/netsite-docs While http://yourschool.com/~yourusername may load from /d3/home/student/amb93/public_html/index.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.