Jick Posted April 24, 2008 Share Posted April 24, 2008 I already posted this on another forum but I never got any response so I thought I would ask here... Is there a more reliable way to get a full server path from a URL than this: <?php define('ABSPATH', dirname(__FILE__) . '/'); $url = 'http://www.myserver.com/subdir/css/main.css'; $parseurl = parse_url($url); $path = ABSPATH . substr($parseurl['path'], 1); ?> That method doesn't seem to work on some servers/configurations. It works on my server but apparently not for some other people. I'm using that code in a script and some people are reporting that it doesn't work. I'm using it like this: <?php define('ABSPATH', dirname(__FILE__) . '/'); $url = 'http://www.myserver.com/subdir/css/main.css'; $parseurl = parse_url($url); $path = ABSPATH . substr($parseurl['path'], 1); $modtime = filemtime($path); $modate = date('Y/m/d \a\\t g:iA', $modtime); echo($modate); ?> The reason I think it's the URL causing the problem is because I had one of the people who reported it as non-working run a test version of the script on his server and the path the script was returning was incorrect. (The test version was exactly the same except I had it echo out $path) For the record, I tested this script on my local server (WAMP) and my production server (standard Linux shared hosting setup) and I didn't have any problems with it. The guy I referred to before is running on FreeBSD or something like that (can't remember exactly) and it doesn't work for him. He's not the only one with the problem though. Others have reported the same issue. Oh, and one other note... The solution has to work on PHP4 and up. A PHP5-only solution won't work for me. Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/102676-url-to-path/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.