I’m trying to create a basic CMS in codeigniter, and would like to be able to open view files inside the backend of the CMS, i.e on a webpage. The advantage of this is being able to upload views directly from a code editor/ftp client, but be able to modify them using the CMS if this option isn’t availble. I know i could do it using a database, but being able to FTP views directly is required.
I’ve tried Googling various things, but the keywords seem to pull up completely different results.
So it’s basically opening the file, putting it’s contents in a form/textarea box, then on saving it saves directly to the file again, but i can’t find any examples!
Thanks in advance!
C.
List Files
Using directory iterator you can make a list of all files of a folder. (in your case the list of all .php files into the views folder)
Get / Set the content of the file
Then using file_get_contents you can retrieve the content of the file.
and using file_put_contents you can set the content of the file.
You can also check
which does the same of file_get_contents and file_put_contents…
As for the validation
You may check before getting the file content if the file is_readable
You may also want to check before setting the content if the file is_writable
Complements
Also, if I were you, I would add a syntax highlighter for your cms, you may want to check the one that is used by some big fish like : Apache, Aptana, Mozilla, Yahoo, WordPress, …
http://alexgorbatchev.com/SyntaxHighlighter/