You can use umask() just before calling fopen (), but umask should not be used if you are on a multi-threaded server - it will change the mask for all threads (for example, this change is at the process level), and not just the one you going to use fopen ().
eg.
$old = umask(000); fopen('foo.txt', 'w'); // creates a 0666 file umask($old) // restore original mask
It would be easier to just chmod () after the fact, however:
fopen('foo.txt', 'w'); // create a mode 'who cares?' file chmod('foo.txt', 0666); // set it to 0666
source share