This is more of a general question about application security.

We have an application that we would like to allow two things in it. First allow to upload a zip file that will populate and create directories and files (php as well) in the application directory. Those files will be part of the actual application (IE: We upload a zip file and the system populates it into the appropriate directory and then we have a new section in our site, Like all kind of Open Source softwares do it Like wordpress, Joomla except that instead uploading the directories and files manually to the FTP we upload it through a zip file from the ACP and it populates the files and directories into the appropriate directories). Same thing applies to the template views we have. We have them made as PHP files inside a certain directory so if an admin would like to edit them he could do that through the ACP and save it directly into the file. The problem here is again because of the template views directory needs to be chmod for read and write it can lead to a serious security flows.

So my question here is, Under those circumstances what should be done in order to both have those options in the system and yet not causing any potential security holes and flows.