DamienRoche Posted September 30, 2008 Share Posted September 30, 2008 Is there a command for obtaining the name of the script being run..obviously a command I would have to run in the script? Can I do this: $thisfile = ///// command I want file_get_contents($thisfile); Basically I want to run my test scripts but also feature the actual code on the same page. Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/126481-solved-get-filename-of-script-currently-being-run/ Share on other sites More sharing options...
discomatt Posted September 30, 2008 Share Posted September 30, 2008 $contents = file_get_contents( __FILE__ ); Link to comment https://forums.phpfreaks.com/topic/126481-solved-get-filename-of-script-currently-being-run/#findComment-654009 Share on other sites More sharing options...
discomatt Posted September 30, 2008 Share Posted September 30, 2008 This will give funny results on included files. For this you may want file_get_contents( $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'] ); I'm 99% sure DOCUMENT_ROOT is derived from the server... but I'm not entirely sure about SCRIPT_NAME... so you may want to sanitize. Link to comment https://forums.phpfreaks.com/topic/126481-solved-get-filename-of-script-currently-being-run/#findComment-654012 Share on other sites More sharing options...
DamienRoche Posted September 30, 2008 Author Share Posted September 30, 2008 Thanks discomatt! __FILE__ works perfectly. I'm running it on a local machine so not sure how that will effect the second method. I'll give the other method a try if I decide to put this online. Thanks again! Link to comment https://forums.phpfreaks.com/topic/126481-solved-get-filename-of-script-currently-being-run/#findComment-654019 Share on other sites More sharing options...
discomatt Posted September 30, 2008 Share Posted September 30, 2008 This should also work, assuming the var is defined $contents = file_get_contents( $_SERVER['SCRIPT_FILENAME'] ); Link to comment https://forums.phpfreaks.com/topic/126481-solved-get-filename-of-script-currently-being-run/#findComment-654024 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.