You might want to try chmodding it to 755 first before throwing an error. `@chmod($dirtmp, '0755');`