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. Quote Link to comment Share on other sites More sharing options...
discomatt Posted September 30, 2008 Share Posted September 30, 2008 $contents = file_get_contents( __FILE__ ); Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment 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'] ); 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.