Unable to write to file - is this a php.ini problem?

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 14583 Views - Last Post: 04 July 2007 - 02:28 AM Rate Topic: -----

#1 Study_Girl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-June 07

Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 12:30 AM

Hi,

I am working my way through a text-book ... "PHP and MySql Web Development" by Luke Welling and Laura Thompson, 3rd edition. I have done these exercises in class as well. I am now at home trying to figure out how to make it work on my own pc!

I am in chapter 2, working through reading and writing to files. I am using a windows system (inetpub/wwwroot directory) and have downloaded and installed php 5 and mysql 5, both are working and am using dreamweaver 8 as an editor. The problem I am having is that when I specify a file to save text to I get the message "unable to process order at this time" which is the message I coded to be shown if the file does not open. Now I have created the txt file manually, and tried all sorts of ways to append/write to that file.

The filepath and its location on my computer is: C:\inetpub\wwwroot\myphpandmysqlsite\orders\orders.txt

I have tried assigning the path in the code to a variable and then passing that variable to the fopen() function and still no joy.

I am wondering if it is possible that I haven't updated my php.ini file enough???

I apologise if there is a topic that has already covered this but I put some keywords through the search engines with no luck...

Please let me know if you need to see what I currently have coded..

Is This A Good Question/Topic? 0
  • +

Replies To: Unable to write to file - is this a php.ini problem?

#2 DilutedImage  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 646
  • Joined: 20-November 06

Re: Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 12:40 AM

It sounds like everything's in order. If you don't mind posting the file-write portion of your code, that might help. Not sure if I can solve your problem, but I'm happy to take a look at it.

Is your code identical to what you did in class? If not, have you tried this same file on another server?
Was This Post Helpful? 0
  • +
  • -

#3 Study_Girl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-June 07

Re: Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 12:52 AM

View PostDilutedImage, on 28 Jun, 2007 - 12:40 AM, said:

Is your code identical to what you did in class? If not, have you tried this same file on another server?



No ... the one we did in class we had to alter as well because we had problems with the $DOCUMENT_ROOT. I have initially tried the book's code (verbatim), then in desperation tried the code from school, then tried to fix it by tweaking it here and there after looking at online tutorials etc. The latest version assigns the full path and file name (yes the file already exists) to a variable ... see below.


	   $outputstring = 'this is a test to see if I have any output';
		
		echo '<p>My output string is '.$outputstring.'</p>';
		
		//open file for appending
		$filepath = "c:/inetpub/wwwroot/myphpandmysqlsite/orders/orders.txt";
		$fp = fopen($filepath, 'ab');
		
		
	if (!$fp)
	{
		echo '<p><strong> Your order could not be processed at this time.   '
		.'Please try again later.</strong></p></body></html>';
		exit;
	}

	fwrite($fp, $outputstring, strlen($outputstring));
	fclose($fp);

echo '<p>Order written.</p>';




Any help you could give would be appreciated...
Was This Post Helpful? 0
  • +
  • -

#4 Styx  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 192
  • Joined: 04-March 07

Re: Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 01:27 AM

It may be that the path is wrong or file permissions are offset.

It should work the way it is, but try using local paths instead of absolute ones:
$filepath = 'orders.txt';

(if the script is in the same directory as orders.txt)

If that doesn't work, try running this script:
<?php
$file = 'orders.txt';
echo substr(sprintf('%o', fileperms($file)), -4);
clearstatcache();
?>

It should tell you the file permissions on that file. Anything 0666 and above is generally good just for testing.

If you want to try changing the permissions, look up how to use chmod

This post has been edited by Styx: 28 June 2007 - 01:55 AM

Was This Post Helpful? 1
  • +
  • -

#5 Study_Girl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-June 07

Re: Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 01:56 AM

View PostStyx, on 28 Jun, 2007 - 01:27 AM, said:

It may be that the path is wrong or file permissions are offset.

It should work the way it is, but try using local paths instead of absolute ones:
$filepath = 'orders.txt';

(if the script is in the same directory as orders.txt)

If that doesn't work, try running this script:
$file = 'orders.txt';
echo substr(sprintf('%o', fileperms($file)), -4);
clearstatcache();
?>

It should tell you the file permissions on that file. Anything 0666 and above is generally good just for testing.

If you want to try changing the permissions, look up how to use chmod


do the permissions for the entire folder need to be both read and write or just the text file itself... am thinking this is my problem because I have already tried the following relative addresses.. where I have specified ...

$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];

running the script...
<?php 
echo $_SERVER['DOCUMENT_ROOT']; 
?>


produces: c:\inetpub\wwwroot

then assigning the filepath...

$filepath = "$DOCUMENT_ROOT/myphpandmysqlsite/orders/orders.txt";

and

$filepath = "$DOCUMENT_ROOT/../orders/orders.txt";

and

$filepath = "./orders/orders.txt";

the last of which was the code we used in school.

I am thinking that it is probably a permissions issue, and have gone into the iis administrator and changed the text file to accept read and write but still no joy... maybe the entire folder must be changed?

Thanking you very much for helping me with this
Was This Post Helpful? 0
  • +
  • -

#6 Study_Girl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-June 07

Re: Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 02:02 AM

View PostStyx, on 28 Jun, 2007 - 01:27 AM, said:

If that doesn't work, try running this script:
<?php
$file = 'orders.txt';
echo substr(sprintf('%o', fileperms($file)), -4);
clearstatcache();
?>

It should tell you the file permissions on that file. Anything 0666 and above is generally good just for testing.


Okay... done. I have run the above code and it produces 0666 ...
Was This Post Helpful? 0
  • +
  • -

#7 Styx  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 192
  • Joined: 04-March 07

Re: Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 02:08 AM

hm, yeah, try setting the permissions for the folder to something like 0777

sorry, even if the file doesn't exist, append will attempt to create it


other than that, in your php.ini, you can try looking for disable_functions and see if anything's listed

This post has been edited by Styx: 28 June 2007 - 02:17 AM

Was This Post Helpful? 0
  • +
  • -

#8 Study_Girl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-June 07

Re: Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 02:43 AM

View PostStyx, on 28 Jun, 2007 - 02:08 AM, said:

other than that, in your php.ini, you can try looking for disable_functions and see if anything's listed


my php.ini looks like this...

Quote

; This directive allows you to disable certain functions for security reasons.
; It receives a comma-delimited list of function names. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
disable_functions =

Was This Post Helpful? 0
  • +
  • -

#9 Styx  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 192
  • Joined: 04-March 07

Re: Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 03:28 AM

hm, try this:

Quote

in the directory you are adding / deleting / modifying files, make sure that the "Internet Guest Account" has access rights to do all of the above. Do this by right clicking on the folder in question, selecting properties. now click the security tab. IUSR_<computer name> is probably not in there, so click "add user..."

now, click advanced and do a search. pick the internet guest account from that list, click ok. now specify the permissions you want that user to have.

if you do in fact already have IUSR_<computer name> in there with all permissions and am still getting this problem, then we have another problem on our hands

let me know your findings on this one.

-Chris

("Accepted Solution" quoted from this topic [cache])

This post has been edited by Styx: 28 June 2007 - 03:35 AM

Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5382
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 05:10 AM

Does your project run on Windows at school?

Is it possible that your php document root is unaware of the full path?
Try using %DOCUMENTROOT/pathtofile rather than C:\fullpath\pathtofile, because using C:\ is going outside of where %DOCUMENTROOT boundry. Can you code find/read the file, or is it only writting to it that has the problem?
Was This Post Helpful? 0
  • +
  • -

#11 Study_Girl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-June 07

Re: Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 06:02 AM

View PostStyx, on 28 Jun, 2007 - 03:28 AM, said:

hm, try this:

Quote

in the directory you are adding / deleting / modifying files, make sure that the "Internet Guest Account" has access rights to do all of the above. Do this by right clicking on the folder in question, selecting properties. now click the security tab. IUSR_<computer name> is probably not in there, so click "add user..."

now, click advanced and do a search. pick the internet guest account from that list, click ok. now specify the permissions you want that user to have.

if you do in fact already have IUSR_<computer name> in there with all permissions and am still getting this problem, then we have another problem on our hands

let me know your findings on this one.

-Chris

("Accepted Solution" quoted from this topic [cache])


Okay I'm getting a little bit lost now... just a little bit. I do have an IUSR_(my computers name) account and I checked this out by going into the iis administration and right clicking on the website's properties. Under the directory security tab I clicked the Edit button in the top area (enable an anonymous access). The IUSR_(my computers name) is in there with iis controlling the password check-box selected. I do not seem to have an advanced button there that allows me to select the users permissions... am I in the right place?

Now when I am in the above area there is a browse button to help you find the names you can select. Inside that there is an advanced button, however window that opens from that does not have any permissions areas either?? So you can see I am a little lost and this is perhaps because I am looking in the wrong place?

Cheers
Was This Post Helpful? 0
  • +
  • -

#12 psykoprogrammer  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 72
  • Joined: 09-October 06

Re: Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 06:19 AM

To check the permissions, actually browse the folder in Windows Explorer, right click on it, and select properties. Go to the Security tab. In that list you will see the Internet Guest Account. Make sure that user has write privileges on your folder.
Was This Post Helpful? 0
  • +
  • -

#13 Study_Girl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-June 07

Re: Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 03:14 PM

View Postpsykoprogrammer, on 28 Jun, 2007 - 06:19 AM, said:

To check the permissions, actually browse the folder in Windows Explorer, right click on it, and select properties. Go to the Security tab. In that list you will see the Internet Guest Account. Make sure that user has write privileges on your folder.



I tried this first, however when I right click on the folder through explorer, and select properties the 4 tabs that I can choose from are:


1. General
2. Sharing
3. WebSharing
4. Customize

This is why I checked it out in iis administrator, as it seemed to give me information about the IUSR you referred to...

Do I need to enable something in preferences somewhere to see the security tab?
Was This Post Helpful? 0
  • +
  • -

#14 Study_Girl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-June 07

Re: Unable to write to file - is this a php.ini problem?

Posted 28 June 2007 - 03:24 PM

View Postpsykoprogrammer, on 28 Jun, 2007 - 06:19 AM, said:

To check the permissions, actually browse the folder in Windows Explorer, right click on it, and select properties. Go to the Security tab. In that list you will see the Internet Guest Account. Make sure that user has write privileges on your folder.



Okay .. In the websharing tab, I selected the radio button to share this folder and have checked both the read and write check boxes....

but still no joy... It is so frustrating when when it is a tweak here or there but after you have tweaked then you are trying and there is still the "could not process your order at this time...please try again later".

I really appreciate you helping me with this
Was This Post Helpful? 0
  • +
  • -

#15 Study_Girl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 27-June 07

Re: Unable to write to file - is this a php.ini problem?

Posted 03 July 2007 - 07:41 PM

I am not sure if anyone is still out there monitoring this topic, however I am still stuck. I have written some php to read the contents of the orders.txt file and that works fine (I manually added a line to that file via notepad!) I can read the line I added manually when executing that page in the internet browser.

Now if I change the mode of the fopen() method from anything other than read, it defers to the failed to open file message (if (!$fp))... Therefore it is definitely a permissions issue regarding writing to the file. I have been enabling everything I can from your descriptions above, and have done some searching for clues on the internet regarding Internet Guest accounts and security but I am not having any luck as nothing I have changed has made a difference. Could someone point me in the direction I should go to enable the Internet Guest User to be able to write to a file.

I did try to change the permissions on the file using the chmod but that brought up an error... see an earlier posting for that info.

Cheers
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2