June 25th, 2013, 06:28 AM
Help on require_once()
I am developing an application using PHP in which one of my calling scripts has a statement in it require_once('reports/prn_intake.php'); in a function create_report(). Now as can be seen my calling script in in the root directory and my report script is in /reports directory in the root. In side the report script I have some hard coded paths for some image files that are inside the /reports directory. Therefore when my calling script calls for this function create_report(), the /reports/prn_intake.php is executed but gives errors because of the hard coded path of the image file inside the report script. The same report is also being used independently through a menu option to run the report and therefore I can not keep two versions of the same report script with changed image paths. How do I tell my prn_intake.php script that it has been called from one script or another based on which I can change the paths inside the report script.
Hope I am making sense in asking this query. I need help in knowing any other way of executing a script by taking the control to that script where it is located rather than using require_once() which actually inserts the script in my calling script at that point. Correct me if I am wrong. Would greatly appreciate some help in this regard.
Thanks in advance!
June 25th, 2013, 09:11 AM
not sure if I understand the problem. So is the problem that you have relative image paths in your report script? And that those paths break when the current directory changes due to the script being included?
In that case, simply use absolute paths (which is generally a good idea, by the way). Use __DIR__ or dirname(__FILE__) to get the absolute path of the directory your script file is in. This path is always the same, regardless of how and where you include the script.
Comments on this post
June 25th, 2013, 12:16 PM