Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

failed to open stream: Permission denied in

Status
Not open for further replies.

haxan

Technical User
Oct 8, 2005
16
NL
Hi all i am running a php scrip on my local IIS server but whenever i run it i get the following erros . coud any one help me fix them.Thanks

Code:
<?		


//collect all the form variables
	$str_hostname	=	trim($HTTP_POST_VARS["hostname"]);	
	$str_user		=	trim($HTTP_POST_VARS["user"]);
	$str_pass		=	trim($HTTP_POST_VARS["pass"]);
	$str_db			=	trim($HTTP_POST_VARS["db"]);
	$str_rootdir	=	trim($HTTP_POST_VARS["rootdir"]);
	$str_audiodir	=	trim($HTTP_POST_VARS["audiodir"]);
	$str_url		=	trim($HTTP_POST_VARS["url"]);
	$str_email		=	trim($HTTP_POST_VARS["email"]);
	$str_avatardir	=	trim($HTTP_POST_VARS["avatardir"]);
	$str_pgtitle	=	trim($HTTP_POST_VARS["pgtitle"]);	
	$setting = 1;


if($HTTP_GET_VARS["install"] == 1)
{
	$fp = fopen('../sources/configure.php', 'w');
    
}
header("location:success_configure.php");
?>

Errors:
Code:
Warning: fopen(../sources/configure.php): failed to open stream: Permission denied in c:\inetpub\[URL unfurl="true"]wwwroot\Music\install\install.php[/URL] on line 20

Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\[URL unfurl="true"]wwwroot\Music\install\install.php:20)[/URL] in c:\inetpub\[URL unfurl="true"]wwwroot\Music\install\install.php[/URL] on line 23
 
Your second error is there because of the first. Headers must be sent before any other output and your first error outputs something. Get rid of the first error, you will get rid of the second.

As for the first, it appears either because the file is not there or because you do not have enough permissions. Make sure that the file (or directory) you're trying to write to has proper permission set for the user under which IIS is running. Bear in mind that the IIS user must have the permissions, not the account you regularly use.

All that, your code seems to make little sense. You open file for writing and then you redirect before you do anything. Is this just a part of the code?

And lastly, you should abandon the old [tt]$HTTP_*_VARS[/tt] for a newer superglobal arrays [tt]$_POST[/tt] and [tt]$_GET[/tt]. The former are not turned on by default in PHP5.
 
vrgabond thank for u reply. Actually the whole code is posted bleow.

well the file is there but could u tell me how to give the file/folder proper permession? An i am using php 4.Furthermore, success_configure.php is in the same folder as install.php file. I be happy if u help me fix this broken code.I even tried to move configure.php to the root folder or to same folder as install but did not work!! Thanks

Code:
<?		

//collect all the form variables
	$str_hostname	=	trim($HTTP_POST_VARS["hostname"]);	
	$str_user		=	trim($HTTP_POST_VARS["user"]);
	$str_pass		=	trim($HTTP_POST_VARS["pass"]);
	$str_db			=	trim($HTTP_POST_VARS["db"]);
	$str_rootdir	=	trim($HTTP_POST_VARS["rootdir"]);
	$str_audiodir	=	trim($HTTP_POST_VARS["audiodir"]);
	$str_url		=	trim($HTTP_POST_VARS["url"]);
	$str_email		=	trim($HTTP_POST_VARS["email"]);
	$str_avatardir	=	trim($HTTP_POST_VARS["avatardir"]);
	$str_pgtitle	=	trim($HTTP_POST_VARS["pgtitle"]);	
	$setting = 1;
 $file_contents = '<?php' . "\n" .
 '/**'."\n".
 'This flag is define whether setting is done with the values or it is blank '."\n".
 '**/'."\n".
 'define("SETTING",\''.$setting.'\');'."\n"."\n".
 '/**'."\n".
 '* Database Constants - these constants are required'."\n".
 '* in order for there to be a successful connection'."\n".
 '* to the MySQL database. Make sure the information is'."\n".
 '* correct.'."\n".
 '*/'."\n".
'define("DB_SERVER", \''.$str_hostname.'\');'."\n".
'define("DB_USER",\''.$str_user.'\');//define("DB_USER", "insert your database details here");'."\n".
'define("DB_PASS",\''.$str_pass.'\');//define("DB_PASS", "insert your database details here");'."\n".
'define("DB_NAME", \''.$str_db.'\');//define("DB_NAME", "insert your database details here");'."\n".
'/**'."\n".
'* Root Paths'."\n".
'**/'."\n".
'define("ROOT_DIR", \''.$str_rootdir.'\');'."\n".
'define("AUDIO_DIR",\''.$str_audiodir.'\');//define("DB_USER", "insert your database details here");'."\n".
'define("URL",\''.$str_url.'\');//define("DB_PASS", "insert your database details here");'."\n".
'define("EMAIL", \''.$str_email.'\');//define("DB_NAME", "insert your database details here");'."\n".
'define("AVATAR_DIR", \''.$str_avatardir.'\');'."\n".
'define("PGTITLE",\''.$str_pgtitle.'\');//define("DB_USER", "insert your database details here");'."\n".
'	?>';

if($HTTP_GET_VARS["install"] == 1)
{
	[b]$fp = fopen('../sources/configure.php', 'w');
    fputs($fp, $file_contents);
    fclose($fp); [/b]
}
[b]header("location:success_configure.php");[/b]
?>

configure code:

Code:
<?php
This flag is define whether setting is done with the values or it is blank 
**/
define("SETTING",'1');

/**
* Database Constants - these constants are required
* in order for there to be a successful connection
* to the MySQL database. Make sure the information is
* correct.
*/
define("DB_SERVER", 'localhost');
define("DB_USER",'root');//define("DB_USER", "insert your database details here");
define("DB_PASS",'');//define("DB_PASS", "insert your database details here");
define("DB_NAME", 'musicbox');//define("DB_NAME", "insert your database details here");
/**
* Root Paths
**/
define("ROOT_DIR", '/[URL unfurl="true"]wwwroot/test');[/URL]
define("AUDIO_DIR",'/[URL unfurl="true"]wwwroot/test/audio');//define("DB_USER",[/URL] "insert your database details here");
define("URL",'[URL unfurl="true"]http://www.localhost/test');//define("DB_PASS",[/URL] "insert your database details here");
define("EMAIL", 'listen@me.com');//define("DB_NAME", "insert your database details here");
define("AVATAR_DIR", '/[URL unfurl="true"]wwwroot/test/avatars');[/URL]
define("PGTITLE",'New Designs');//define("DB_USER", "insert your database details here");
	?>
 
I don't run IIS server, so maybe you should ask at that specific forum (forum41).
 
as vragabond suggests - it's most likely to be a permissions issue.

first: use an absolute path in the fopen, if i were you. it removes the chance of getting it wrong.

second: in windows explorer navigate to the necessary file. right-click and select properties. in the security tab make sure the IIS user (normally IUSR_[machinename]) has the permission to write to the file. that should be it.

the alternative is to use windows authentication on your site. to do this, open up the IIS manager and go to the directory security tab of the relevant web. unclick anonymous access and select integrated windows authentication. that will tell IIS to authenticate you and will then run the process under your user account.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top