-4

I created a web application with a file browser. I'm trying to add a functionality where the user can change the chmod/permissions via an ajax request which is handled via PHP on the back-end.

(Side Note: I'm running my local with WAMP)

So initially, I'm reading the permissions with this

substr(sprintf('%o', fileperms($relativePath)), -4)

to get this format (0777, 0644, etc), if not it returns something like 32726. This info is used to be displayed in the UI for the user to know whats current.

However, when I run the script, I set it to 0777 and it seems to run fine. But then when I read the file again, it returns 0555 or 0444. Anyone know what I'm missing?

Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74
SReca
  • 643
  • 3
  • 13
  • 37

2 Answers2

0

Does your web server own the files it is trying to change the permissions on? You can check whether chmod ran correctly or failed by testing its return value. It will return FALSE if the webserver did not have permissions. For more information you can read: http://php.net/manual/en/function.chmod.php

<?php 

$is_success = chmod("myfile.pdf", 777);
if($is_sucess) {
     echo "success<br />\n";
}
  • I actually have a very similar setup on the PHP end... The issue isn't whether its successful or not, but rather, once I process the request of changing perm to 777 and read the file again using the code snippet I provided above, it returns 555 or 444. – SReca Jun 03 '16 at 23:11
0

I realized this was not an issue, but rather the chmod command does not work properly on a windows/apache setup.

SReca
  • 643
  • 3
  • 13
  • 37