PHP – Chmod-ed to Windows hell and back

March 10, 2009 in PHP

Today has not been a good day.

With various things going wrong, I was please that I had got the file upload code done for a site i’m working on. All I needed to do was make sure that the file had the right permissions and then edit it via GD (via an image editor class i have). Here’s where the trouble started..

I started off by chmoding the file to 777 and then trying to do the resize.. this threw an error with permissions.. so i looked at the file.. Read Only.. strange I thought.

Then I checked the folder and that had a weird green square instead of the checkmark in the checkbox. I tried to remove the read only attribute off of this and hte file.. and it kept coming back.. I went all around hte houses, trying all sorts of techniques .. to no avail.

@auroraeosrose in the PHPWomen IRC channel helped a lot as did Dreis.. (thanks muchly)..

After backing up the files and formatting the drive, to reinstalling the Apache/PHP/MySql stack I was no clearer to the answer as to why the file was always ending up with read only permissions..

Finally it came down to the 1 thing that I had overlooked.. the chmod in the code .. the second parameter was 777. I thought this was correct. Aparrantly not. The second parameter of the chmod function requires an octal code.. thus prefixing the 777 with a 0 (zero) fixed the whole issue.

Boy did i really feel dumb today.

So to wrap up, remember to always pass a FOUR digit code through to chmod or face the annoyance and headache I got today.