Hmmm,
One question I would initially have is what operating system is your PHP code running on?
If it is linux then I would suggest possibly running system("chmod +w $filenameORdirname"); (not sure if correct syntax ;-P). This would basically chmod the permissions for the file or directory name you specify, of course if you want it to modify a directory then I woudl suggest adding a -r for recursion. You could also possibly run a test first to see if a fopen fails intially and then counter-act that, so something like:
if(!$fp = fopen("$filename".".txt", "w+")) {
/This would fail if the file could not be created/opened with
write privelages so lets change the priv's and retry /
if(!system("chmod +rw .")) { //could not change permissions
/You are running as a user that does not have the
rights to modify the permissions for the current directory (.)
OR you are trying to create a file that is owned by
another system user/group or open a file for writing that is
owned by another system user/groupthat you are not with
ie.. -rwxrwx--- user group other [you would fall into other
if the file/dir was owned by another system user that you
are not running as which does not have permissions due to
the ---]
r = read, w = write, x = execute, - = denied/not specified
(ignore the initial -)
/
//NOTE:You could possibly even run a sudo command here to
//counter not having permissions by changing to root for
//permission change
echo("Error: Could not change file permissions with".
"system() call");
exit; //pointless from here...
} else {//Permissions changed to allow read & write}
//if I get this far let's try re-opening the file yet again
if (!$fp= fopen("$filename".".txt", "w+")) {
//I still failed, something else is not allowing me to open this
//file to write to, possibly disk space?
echo("Error: Changed permissions but still cound not open".
" or create ".$filename.".txt file for writing");
} else {/Opened file and handed over to $fp/ break;}
} else { /Opened file and handed over to $fp/}
//continue to write to the file and then don't forget the fclose($fp)
Of course I dont know if a windows implementation would work or not, but I'd trying running system() with a attrib +W command or something...
Just a thought... 😉