0

Have a abstract how-to question which I haven't found a solution. Lets say you built a plugin for a CMS like wordpress, I'm using a MCMS called GetSimple. And now within that plugin.. when a button is clicked by the user... two external php files have their code ran and their output taken and put collectively into a single static file.. say a html or css file.

So then in this kind of scenario... how can you (within the plugin) run an external php file without effecting the current page you are on, then take that output and put it as a string into a variable.. repeat this for another php file... then take the two string outputs, merge them... then put them into a single static file?

This has proven to me to be a very difficult task. for more details you can see this question: https://stackoverflow.com/questions/15080163/how-to-create-a-file-with-php

So how would you go about doing this? I was looking at the possibility of saving each file's output into separate xml files and then merging those xml files... but the problem still remains of running external php and putting that data somewhere without affecting the current page PHP you are on.

2
  • use AJAX, get output from one php file, then the other, and put them together. Commented Feb 26, 2013 at 3:06
  • @kennypu then problem I think that makes this not possible is the php files are not directly accessible from a user... it's only accessible server side. Security built in to the CMS does this... that's why I have to get the content to run similiar to include(). but without actually including it on the current php page... shell_exec() might work for that.. and I'd run it on a If $_POST only Commented Feb 26, 2013 at 3:48

1 Answer 1

1

If you can generate the response on the server-side, you could simply run those PHP scripts using for example shell_exec() or using Symfony2 Process Component, then gather the results using file() or file_get_contents() functions.

If you need to have this things generated on button click, you must notify server to handle that tasks, and to do so you need to make an AJAX calls calling that scripts using methods I've told you above.

Sign up to request clarification or add additional context in comments.

3 Comments

I can do this with if $_POST instead of AJAX right? Do you have an example of a code block to do this using shell_exec()?
See the PHP docs, it's really simple - shell_exec('<PHP FILE PATH>');. You can do it on POST request, but AJAX is more convenient for clients. :)
I ended up just making a 2nd file with tags for variable replacements and used file_get_contents to gather the file and str_replace to change the tags to variables then saved out with file_put_contents.. works without any issues and accomplished what I needed! :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.