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! Link to comment https://forums.phpfreaks.com/topic/41880-convert-url-to-local-path/ 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? Link to comment https://forums.phpfreaks.com/topic/41880-convert-url-to-local-path/#findComment-203200 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. Link to comment https://forums.phpfreaks.com/topic/41880-convert-url-to-local-path/#findComment-203208 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/" Link to comment https://forums.phpfreaks.com/topic/41880-convert-url-to-local-path/#findComment-203562 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... Link to comment https://forums.phpfreaks.com/topic/41880-convert-url-to-local-path/#findComment-203900 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! Link to comment https://forums.phpfreaks.com/topic/41880-convert-url-to-local-path/#findComment-203922 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? Link to comment https://forums.phpfreaks.com/topic/41880-convert-url-to-local-path/#findComment-203967 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 Link to comment https://forums.phpfreaks.com/topic/41880-convert-url-to-local-path/#findComment-203972 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.