Welcome Guest, Not a member yet? Register   Sign In
Call A Raw PHP File
#1

Hello everyone,

I'm currently working on a way to be able to call raw PHP files inside the Code Igniter's application folder. The idea is that we have an internal tool that accepts PHP files as input. It then runs these PHP files for processing. The way it can run is not limited to the command line but can also be independent and can be called via the browser.

I have tried a couple of solutions like the following:
1. Created a raw PHP file and included index.php file
2. Create a route with route name as follows, "{file}.php", then reference it to the correct controller/method.
3. Hooks

All of these doesn't give me the solution that I want. I'm asking the community for suggestions to solve my issue. Or recommendations if this kind of task is not applicable on Code Igniter.

I'm currently using Code Igniter 2.

Thanks in advance.

Regards,
Rolly
Reply
#2

Sometimes when I have a file that I want to run outside of CodeIgniter, I'll just put it in a directory that exists at web root. Local Apache configuration is normally set to route all requests through CodeIgniter, except when files exist, and those are run or run/served as stand-alone scripts.

If you'd rather run files from CodeIgniter, you could do something with the routes config, and then inside your controller just use PHP's include function to process the script. Be careful not to allow a person to execute a script by modifying the URL, or you could be letting them run any file on the server. Instead, have a pre-defined set of routes that must be matched in order that a specific php script be included.

Both ideas presented are just basic php and/or webserver usage.
Reply
#3

Thank you for your answer sir skunkbad. The end goal is to run raw PHP files inside Code Igniter without the restriction of just running it on command line. Do you think your "routes" solution would solve this? The first idea, the stand-alone scripts, is what I'm currently aiming to do since I can't seem to make CI run these raw PHP files.
Reply
#4

There is another old (CI2) idea: https://github.com/bcit-ci/CodeIgniter/w...ide-script
Reply
#5

(01-17-2017, 12:22 AM)minianorollyc Wrote: Thank you for your answer sir skunkbad. The end goal is to run raw PHP files inside Code Igniter without the restriction of just running it on command line. Do you think your "routes" solution would solve this? The first idea, the stand-alone scripts, is what I'm currently aiming to do since I can't seem to make CI run these raw PHP files.

Yes, it will work, just heed my warning regarding access to files. Ensure somebody can't view something like:

../../../../../your_passwords.txt
Reply




Theme © iAndrew 2016 - Forum software by © MyBB