Warning: file_put_contents (/var/www/public/temp.txt) [function.file-put-contents]: stream could not be opened: permission denied in /var/www/public/newtest.php on line 8
There is so much bad here.
Let's start with the fact that you really want to save files that can be written in the httpd format, far from your code - of course, in a separate directory, preferably outside the root directory of the document.
chown -R apache: apache www and set permissions 777 to folders
And you checked what the permissions really were? By the way, see Also the paragraph above - if you made the entire site writable to everyone, then you just ask for troubles. Of course, you will not change BOTH your owner and permission.
SELinux ? ( sestatus root). , , , , , SELinux.
.