Then I use another script to create a file and put some contents into it, like so:

fwrite( fopen('folder/test/filename', 'w'), 'Test text' );

This, however results in:

Warning: fopen() [function.fopen]: SAFE MODE Restriction in effect. The script whose uid is XXXXX is not allowed to access ...

If, however, I try to create the file in the parent directory, like so:

fwrite( fopen('folder/filename', 'w'), 'Test text' );

it works fine. The parent folder ('folder' in the above example) is set to 777 'manually', so the 'SAFE MODE Restriction' only appears when I first create a folder using mkdir and then try to write in the same folder. How can this be?

Check the permissions on the test folder.Mght be that SAFE MODE does not allow you to mkdir a dir with 777 permissions.This might help.
–
VladSep 20 '12 at 8:47

Um.. how do I check? Actually looking at the permissions in terminal shows dr-xr-xr-x for the newly created folder, seems like PHP doesn't follow orders and set it to 777 as in the script. Might this have something to do with the SAFE MODE-issue?
–
MatteSep 20 '12 at 8:52

@VladTeodorescu Good tip, tried it out, and the permissions for the folder are now: drwxrwxrwx. However the SAFE MODE restriction still appears... Any ideas?
–
MatteSep 20 '12 at 9:00

That would be a great idea, but as I'm not the owner of the server this is not an option. I'm looking for a work around running the current version (5.1.6). (Believe me, I've tried to convince them to upgrade before with no luck so far...).
–
MatteSep 20 '12 at 9:32