PHP newbie question

Discussion in 'Web Design and Development' started by maxterpiece, Feb 9, 2007.

  1. maxterpiece macrumors 6502a

    maxterpiece

    Joined:
    Mar 5, 2003
    #1
    I'm trying to add a string to a TXT file on my webserver (hosted on asmallorange), and I get this error:
    Why can't I write to the file? How can I give my script permission to edit the file? Both the file and the script are located in the exact same location on the server.

    Thanks for any help you can provide!

    Code:
    //make addition
    $myFile="story.txt";
    $fh = fopen($myFile, 'a+');
    fwrite($fh, $addition);
    
     
  2. pengu macrumors 6502a

    Joined:
    Mar 20, 2005
    Location:
    Diddily Daddily...
    #2
    you'll probably find that the files in "your" webspace have an owner of "yourusername" but the webserver (apache) process is running as the http or web user, and so it doesnt have access to modify those files. ideally, see if you can give the file(s) a group that corresponds to the apache process, and make it group writable.
     
  3. bbarnhart macrumors 6502a

    bbarnhart

    Joined:
    Jan 16, 2002
    Location:
    Stilwell, Kansas
    #3
    I had this exact problem a while back. It's a permissioning issue. Contact your host and ask then to set the permissions up so you can open and write data using php.
     
  4. ijimk macrumors 6502a

    ijimk

    Joined:
    Jun 17, 2004
    Location:
    Here
    #4
    Weird I had a similar problem like this last night :eek:
     
  5. maxterpiece thread starter macrumors 6502a

    maxterpiece

    Joined:
    Mar 5, 2003
    #5
    So I emailed my host and they said
    Well i would rather still have access to my file, so I'd prefer not to have them give just the webserver permission, but I don't know what they are talking about - How do I change "the permissions to 664 (allow your id and nobody write perms)." I apologize if this is something elementary, again I don't really know what I'm doing.

    Thanks for the responses everyone and thanks for any further help you can provide!
     
  6. fall3n macrumors 6502

    Joined:
    Aug 17, 2006
    #6
    You'll need to log into your web server via your FTP program, I use transmit. Then find your file and right click on it. Go to "Get info", much like your Mac OS X interface, you'll notice a portation at the bottom of the window that pops up that lets you check and uncheck certain permissions. Change them to as needed and hit apply. 777 is your ultimate anyone can read and edit everything. Hope this helps.
     
  7. pengu macrumors 6502a

    Joined:
    Mar 20, 2005
    Location:
    Diddily Daddily...
    #7
    DO NOT just go setting "777" rights without exploring other options. it means ANYONE who has access to the web server's file structure can modify your file.


    I strongly suggest you explore the options mentioned above, (either ask the host for help, or change the group ownership of the file to match that of the apache process).
     

Share This Page