Use of PHP script in a plugin

I couldn't find a plugin that met my needs so I am building one. I ran into some issues that I have not found the answer to. Hoping someone can help 

The plugin I am having trouble with is a media manager.  I want it to work a bit like the one on WordPress becuase that one is simple and I have users who need simple. This plugin is designed to work with many other plugins I am creating to add several features to my web site for writers.  I use it to attach a "featured " image to blog posts as well as to my meeting, chapter, event, features  etc..  entities implemented in my other plugins. 

The media manager presentation is mostly javascript. and CSS.   The plugin injects these by extending the proper views.  As it stands now I all I have to do to implement the media manager on any page of the site is to include a div with a certain id and a button with a certain class name.   I plan to extend a view at a later time so the div is put on every page. The div is hidden and empty until the javascript fills it on page load and the button toggles the view to on.  The button may need to be added manually when the view is created.   

Where my question comes in is when it comes to uploading the files. The javascript provides a drag and drop or browse interface to select files and then previews them and uploads them.

I am having trouble figuring out the ELGG way to route, place, and run the files needed to actually do the uploading and the fetching of the files. These are not views and they are not and do not work as actions when utilized via ajax.   

The larger issue is that any php files placed in the ELGG  web space are passed to ELGG instead of handled as usual. I use NGINX but I know that is not the issue.  When I set up a directory for the scripts and browsed to the correct file they downloaded rather than executed. This happens to a simple PHP file with a single echo statement a well.   I tried to set up a separate location directive but that did not work. 

So, I placed the files in an entirely different web tree.  One is  and the other is  this works, That is to say the scripts execute and upload the files as expected.  This is NOT the way I want this to work of course       

Has anyone had success using AJAX to talk to PHP files in an ELGG plugin? 

Perhaps the php code could be put in the plugins class?  If so I am at a loss as to how to reach it via a post from the javascript code. 

Maybe I need I would need to expose the code via web services? 

Any help or even hair-brained ideas as to how I can make this plug in a completelty portable item wold be appreciated?    


  • Thank you for your reply.  Hop you are having a great day.   

    I have read a slightly different version of this Elgg / ajax guide  I will take a closer look at this one. The inbuilt ajax structure seems very efficient at working with  Elgg objects but I have been unable to get it to work with my upload script.    

    The Filereader API does a great job in reading files by URL, especially when across domains.   My script uses the fetch API  which works quite well.  The upload script works as expected when tested with Postman I just can not seem to reach it in an Elgg plugin.  I will look at the register_ajax function .