Page 1 of 1

Permission denied

Posted: Tue Sep 26, 2006 8:48 am
by mojeIme
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi ,i am trying to create a simple function for  creating/updating text files. It just can't open the ile with the writing permissions. I don't understand
how can

Code: Select all

if (is_writable($filename)) { //ok!
}
... be passed , and then it returns me this error:
fopen("c:\Korisnici\Domains\myDomain.ba\ROOT\Inetpub\wwwroot\new\WS/test/txt/kunde2.txt", "w") - Permission denied
Here is the function:

Code: Select all

function putDataToFile($filename, $data, $writeAttributes='a') {
	    $filename = realpath("../../WS/") . "/" .$filename;
		if (is_writable($filename)) {
			if (!$handle = fopen($filename, $writeAttributes)) {
				return "Cannot open file ($filename)";
				
			}
			// Write $data to our opened file.
			if (fwrite($handle, $data) === FALSE) {
				return "Cannot write to file ($filename)";
			}
   			return "Success, wrote ($somecontent) to file ($filename)";
   			fclose($handle);
		}else {
   			return "The file $filename is not writable";
		}
	}
Note that i found $filename ok,as i tested it with "fread".
Please give me some advice.
Thanks in advance.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Sep 26, 2006 9:10 am
by Rovas
I see that you' re using Windows so replace
/
with
\
and set the permission for the user (I_WAN) to read and execute.
Read this tutorial http://webdevelopment.developersnetwork ... Article=34
If I am correct you' re using IIS as a server so go to http://www.iis-resources.com/ for more tools, information and advice.

Posted: Tue Sep 26, 2006 9:20 am
by mojeIme
Thanks Rovas!

Posted: Tue Sep 26, 2006 3:03 pm
by feyd
the PHP constant DIRECTORY_SEPARATOR may be of use or interest.