Solved

Writing to file using PHP on IIS

Posted on 2007-11-28
4
1,539 Views
Last Modified: 2012-06-27
I am using PHP on my IIS server.

I am trying to write to a file using PHP in a file at http://localweb/local/Management/testfile.php. I want it to write to an exsiting file:-

C:\Inetpub\wwwroot\Local\Management\Files\Registrations\test.txt

testfile.php contains the following attached code snippet.

I have set the open_basedir in PHP.INI and phpinfo reports it to be:-

C:\Inetpub\wwwroot\Local;C:\Inetpub\wwwroot\mydomain.com;C:\Inetpub\wwwroot\wiki

I am getting the error message:-

"Warning: fopen(Files\Registrations\test.txt) [function.fopen]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\Local\HostingManagement\testfile.php on line 4"

I have tried various combinations of paths etc and none of the give me any joy.

Can anyone suggest how I get this working, or what I am doing wrong?



<?php
$filename = "Files\\Registrations\\test.txt";
$newdata = "test data";
$f=fopen($filename,"w");
fwrite($f,$newdata);
fclose($f);  
?>

Open in new window

0
Comment
Question by:cescentman
  • 2
4 Comments
 
LVL 20

Expert Comment

by:steelseth12
ID: 20366387
First try

$filename = "Files".DIRECTORY_SEPARATOR."Registrations".DIRECTORY_SEPARATOR."test.txt";

if that doesnt work then try

$filename = "Files".DIRECTORY_SEPARATOR."Registrations".DIRECTORY_SEPARATOR."test.txt";

chmod($filename,0666);

if that doesnt work then open your ftp software and set the permissions from there.

Right click on the file you should see something like permissions or attributes then change them
0
 
LVL 1

Author Comment

by:cescentman
ID: 20366725
I will try this but does chmod have any effect on a windows server? there is no need for ftp as in this case the path is local and I'm not using ftp.
0
 
LVL 17

Accepted Solution

by:
nplib earned 500 total points
ID: 20367246
change the permission on the C:\Inetpub\wwwroot\ for the IUSR user to have write privileges
0
 
LVL 1

Author Comment

by:cescentman
ID: 20368638
So simple but so effective, fantastic thanks.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question