Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: PHP fopen() problems

  1. #1
    FlyByWire128 is offline Newbie
    Join Date
    Feb 2007
    Posts
    16
    Rep Power
    0

    PHP fopen() problems

    So, I'm trying to write a PHP script to open a text file and edit it. I've made all the permissions 777, and I still get:

    Warning: fopen() [function.fopen]: failed to open stream: Permission denied in [directory] on line 3

    I can't seem to figure out why this isn't working. Any suggestions would be appreciated.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Jordan Guest
    Could you post your fopen() code and the file path/variable?

  4. #3
    Lop's Avatar
    Lop
    Lop is offline Speaks fluent binary
    Join Date
    May 2006
    Posts
    1,178
    Rep Power
    30
    Sounds like you have the wrong path name. Could you show us some code and maybe a "pwd" from the server in the directory the file is at?

  5. #4
    FlyByWire128 is offline Newbie
    Join Date
    Feb 2007
    Posts
    16
    Rep Power
    0
    The code is very simple:

    Code:
    <?php 
    echo getcwd();
    $fp = fopen("tuesdayR.txt", "w+");
    fclose($fp);
    
     ?>
    No matter what I do, as long as I'm not just trying to read the file (fopen(file, r)) I get the same error:

    E:\users\orchestra\Rehearsals
    Warning: fopen(tuesdayR.txt) [function.fopen]: failed to open stream: Permission denied in E:\users\orchestra\Rehearsals\testPHP.php on line 3

    Warning: fclose(): supplied argument is not a valid stream resource in E:\users\orchestra\Rehearsals\testPHP.php on line 4
    PHP Warning: fopen(tuesdayR.txt) [function.fopen]: failed to open stream: Permission denied in E:\users\orchestra\Rehearsals\testPHP.php on line 3 PHP Warning: fclose(): supplied argument is not a valid stream resource in E:\users\orchestra\Rehearsals\testPHP.php on line 4
    Last edited by FlyByWire128; 07-24-2007 at 05:21 AM. Reason: Forgot something...

  6. #5
    Lop's Avatar
    Lop
    Lop is offline Speaks fluent binary
    Join Date
    May 2006
    Posts
    1,178
    Rep Power
    30
    Try adding the path:

    Code:
    $fp fopen("E:\\users\\orchestra\\file\\path\\here\tuesdayR.txt""w+"); 

  7. #6
    FlyByWire128 is offline Newbie
    Join Date
    Feb 2007
    Posts
    16
    Rep Power
    0
    I tried adding the whole path as suggested, but no luck. It's still telling me permission denied, and I can't figure out why... Every suggestion I've ever heard when this happens is to change the permissions, but they're all set, so that shouldn't be a problem. Any other suggestions?

  8. #7
    Jordan Guest
    Have you tried a different file? Maybe it isn't the file permissions but the directory permissions. I've ran into this on Windows Machines before.

  9. #8
    Crane's Avatar
    Crane is offline Programming Expert
    Join Date
    Nov 2005
    Posts
    398
    Rep Power
    25
    How did you change the permission to 777 in Windows? You mean you just made it world?

  10. #9
    FlyByWire128 is offline Newbie
    Join Date
    Feb 2007
    Posts
    16
    Rep Power
    0
    I've tried different files, I've tried different directories, I've tried files that already exist, I've tried creating a new file using fopen(). I'm using SmartFTP, and according to it, the directory, and the files are all 777 permissions... I don't know what else to do.

  11. #10
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    Code:
            $filename "tuesdayR.txt";
            echo 
    realpath($filename);
            
    $filename realpath($filename);

            if (
    is_readable($filename)) {
                    echo 
    "<br />The file is readable...<br />";
            } else {
                    echo 
    "<br />The file is not readable...<br />";
            }

            if (
    is_writable($filename)) {
                    echo 
    "The file is writable...<br />";
            } else {
                    echo 
    "The file is not writable...<br />"
            
    }

            if (
    file_exists($filename)) { 
                    echo 
    "File exists...<br />";
            } else {
                    echo 
    "File cannot be found...<br />";
            }

            
    $handle fopen($filename"w");
            
    fwrite($handle'Yo, sup?');
            
    fclose($handle); 
    Post the results of this...
    Last edited by John; 07-24-2007 at 03:34 PM.

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Does fopen 'stream'
    By bbqroast in forum C and C++
    Replies: 1
    Last Post: 07-28-2011, 04:36 PM
  2. Replies: 13
    Last Post: 05-04-2011, 07:14 PM
  3. fopen with binary mood
    By peter576 in forum C and C++
    Replies: 7
    Last Post: 04-10-2010, 04:39 PM
  4. What mode should i use at fopen()? r, r+, w+b???
    By tirengarfio in forum C and C++
    Replies: 3
    Last Post: 08-13-2008, 09:06 PM
  5. fopen question
    By cpd2591 in forum PHP Development
    Replies: 2
    Last Post: 08-08-2007, 10:46 PM

Tags for this Thread

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