Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,671 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,182 people online right now. Registration is fast and FREE... Join Now!




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

2 Pages V  1 2 >  
Reply to this topicStart new topic

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

Study_Girl
post 27 Jun, 2007 - 11:30 PM
Post #1


New D.I.C Head

*
Joined: 27 Jun, 2007
Posts: 13


My Contributions


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..

User is offlineProfile CardPM

Go to the top of the page

DilutedImage
post 27 Jun, 2007 - 11:40 PM
Post #2


D.I.C Addict

Group Icon
Joined: 20 Nov, 2006
Posts: 642



Thanked 6 times

Dream Kudos: 25
My Contributions


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?
User is offlineProfile CardPM

Go to the top of the page

Study_Girl
post 27 Jun, 2007 - 11:52 PM
Post #3


New D.I.C Head

*
Joined: 27 Jun, 2007
Posts: 13


My Contributions


QUOTE(DilutedImage @ 28 Jun, 2007 - 12:40 AM) *

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.

CODE


       $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...
User is offlineProfile CardPM

Go to the top of the page

Styx
post 28 Jun, 2007 - 12:27 AM
Post #4


D.I.C Head

Group Icon
Joined: 4 Mar, 2007
Posts: 192



Dream Kudos: 225
My Contributions


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:
CODE
<?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 Jun, 2007 - 12:55 AM
User is offlineProfile CardPM

Go to the top of the page

Study_Girl
post 28 Jun, 2007 - 12:56 AM
Post #5


New D.I.C Head

*
Joined: 27 Jun, 2007
Posts: 13


My Contributions


QUOTE(Styx @ 28 Jun, 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:
CODE
$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...
CODE
<?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
User is offlineProfile CardPM

Go to the top of the page

Study_Girl
post 28 Jun, 2007 - 01:02 AM
Post #6


New D.I.C Head

*
Joined: 27 Jun, 2007
Posts: 13


My Contributions


QUOTE(Styx @ 28 Jun, 2007 - 01:27 AM) *


If that doesn't work, try running this script:
CODE
<?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 ...
User is offlineProfile CardPM

Go to the top of the page

Styx
post 28 Jun, 2007 - 01:08 AM
Post #7


D.I.C Head

Group Icon
Joined: 4 Mar, 2007
Posts: 192



Dream Kudos: 225
My Contributions


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 Jun, 2007 - 01:17 AM
User is offlineProfile CardPM

Go to the top of the page

Study_Girl
post 28 Jun, 2007 - 01:43 AM
Post #8


New D.I.C Head

*
Joined: 27 Jun, 2007
Posts: 13


My Contributions


QUOTE(Styx @ 28 Jun, 2007 - 02:08 AM) *


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 =
User is offlineProfile CardPM

Go to the top of the page

Styx
post 28 Jun, 2007 - 02:28 AM
Post #9


D.I.C Head

Group Icon
Joined: 4 Mar, 2007
Posts: 192



Dream Kudos: 225
My Contributions


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 Jun, 2007 - 02:35 AM
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 28 Jun, 2007 - 04:10 AM
Post #10


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


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?
User is offlineProfile CardPM

Go to the top of the page

Study_Girl
post 28 Jun, 2007 - 05:02 AM
Post #11


New D.I.C Head

*
Joined: 27 Jun, 2007
Posts: 13


My Contributions


QUOTE(Styx @ 28 Jun, 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])


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
User is offlineProfile CardPM

Go to the top of the page

psykoprogrammer
post 28 Jun, 2007 - 05:19 AM
Post #12


D.I.C Head

Group Icon
Joined: 9 Oct, 2006
Posts: 68



Dream Kudos: 50
My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:01AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month