Permission denied

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mojeIme
Forum Newbie
Posts: 22
Joined: Sat Jul 29, 2006 8:58 am

Permission denied

Post 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]
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Post 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.
User avatar
mojeIme
Forum Newbie
Posts: 22
Joined: Sat Jul 29, 2006 8:58 am

Post by mojeIme »

Thanks Rovas!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the PHP constant DIRECTORY_SEPARATOR may be of use or interest.
Post Reply