Results 1 to 5 of 5

Thread: File not opening in php

  1. #1
    Join Date
    Dec 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default File not opening in php

    Hi.
    I have my home directory on my departments server. Somehow I am not
    able to write to a file using a php code,
    $myFile = "trial3.txt";
    $fh = fopen($myFile, "a+") or die("can't open file");
    fwrite($fh, "teststring\n");
    fclose($fh);

    Instead of a+ if i use r or w or anything, it does not work. Could this
    be a permission thing? The entire directory had a 777 permission and
    even i after i created a file and chmod'ed 777 to it, the code couldnt
    open it. What could be the matter? It doesnt go away if i change it to
    'w' or 'w+' or 'r' or 'r+'.

    When i use the shell to parse the php script, it does actually write it to the file. But not when i open the url in the browser. What could be the matter?

    Rahul

  2. #2
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    If I recall correctly fopen requires full path to file to work, unless you set third parameter to true (use_include_path)

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    The file also has to be on the remote server you're working on. I don't think using the full path will be any use either, using what I previously said to back it up.
    So. Put the file in your remote directory, or folder.
    - Mike

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    also, make sure that the directory has writable permissions or is at least owned by the same user as the PHP is running on your machine. I've run into this problem tons of times. If the directory was created by PHP, then it should be alright, but if it was not, you may have to chmod the directory to 777. Just a few suggestions.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Oh yes. Exactly right, I forgot about that. It has to be 555 if made with PHP I'm pretty sure.
    - Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •