When I manually copy files from one folder to my www folder, i cannot read those files using php because those copied files do not have read permission (i am on ubuntu linux) so what I have to do is run sudo chmod -R 777 /var/www/html/ followed by my password.
I ahve to run this command manually, but I want to automate this in my script, The chmod() function or exec(‘sudo chmod -R 777 /var/www/html/’); does not work as they dont change the desired permission.
You do not need to run chmod as root if the file belongs to your user. So leave out sudo. Also, instead of running chmod after copying files you could set umask to an appropriate value.
@phantom007, sounds like you have a much larger problem than what you are telling us about.
First off, NEVER change the files to 0777, that gives everyone on the server read, write, and execute access to those files. That is dangerous.
Second, sudo in a PHP command will never work. As you don’t have an easy way of providing the authenticating password to sudo. So anything that depends on sudo will be a manual process – not what you want.
So let’s get back to the beginning here with a few questions.
What web server are you using? Apache? nginx? lighttpd?
Is this a development server? Or a live production site server?
Any reason you are using the /var/www/ folder? Versus creating a virtual directory in a different location?