1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Permission denied when using fopen

Discussion in 'PHP' started by cellularnews, Apr 22, 2006.

  1. #1
    I am moving a site to a new server - just a straight copy across.

    The site is written in PHP.

    The main core script is causing problems though - it builds a series of static files using a fairly normal fopen command to create or edit files.

    On the old box - works fine. The new box - gives me the following error (for example):

    Warning: fopen(../archive/mini_Interviews.txt): failed to open stream: Permission denied in /home/virtual/site10/fst/var/www/html/administ/all.php on line 1759

    I have set the server PHP to safe mode off, shows errors. The folder permissions seem OK. As far as I can tell, the new server is now set up identically to the old sever.

    But obviously something is not right.

    I wonder if the ownership of the folder/files is an issue - although it never has been before, and I am not totally sure how to fix that if it is the problem.

    Editing the script to create the files in the same folder as the script itself actually seems to work.

    I tried referencing the target folder using the full server path - did not work.

    It would seem then (possibly) that the issue relates to the script sitting in the same folder as the files it is trying to create ?

    Any clues as to what to look for so I can fix this issue ?
     
    cellularnews, Apr 22, 2006 IP
  2. tomzx

    tomzx Peon

    Messages:
    385
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    well, it could be that the script doesn't known is relate position compared to the script it want to reach. Are you going to write to this file? If so, it's possible that your script only open it as a buffer format so it cannot be edited (nor opened because it thinks it's a url). That would explain why the file being in the same folder makes it work.
     
    tomzx, Apr 23, 2006 IP
  3. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Some hosts disallow fopen using a firewall. Your host may do this but allow fopen within a folder.
     
    mad4, Apr 24, 2006 IP
    Phynder likes this.
  4. tomzx

    tomzx Peon

    Messages:
    385
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    or allow_url_fopen is not enabled, and you're pointing to a url? (I'm not sure since I can't see the full file address in the fopen query)
     
    tomzx, Apr 24, 2006 IP
  5. shino

    shino Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This problem is there for me to in the godaddy server.

    any way do you want to open the file in read mode or write mode

    try with fopen("filename ", "r");
     
    shino, Apr 24, 2006 IP
  6. tomzx

    tomzx Peon

    Messages:
    385
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    godaddy as a huge list of restriction compared to the general web hosting package.
     
    tomzx, Apr 24, 2006 IP
  7. legend2

    legend2 Well-Known Member

    Messages:
    1,537
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    115
    #7
    godaddy has restrictions.

    anyway if you are using fopen with a w glag for writing, make sure the folder (archive) is owned by you (obviously if you're using godaddy) and that you user has a permissions (+w) in there. (chmod it to 777 anyway).

    But again, I'm sure it's godaddy's side.
     
    legend2, Apr 24, 2006 IP
  8. Phynder

    Phynder Well-Known Member

    Messages:
    2,603
    Likes Received:
    145
    Best Answers:
    0
    Trophy Points:
    178
    #8
    You rock! I was having the same problem and spent almost 3 hours looking for clues via Gaagle and found nothing relevant. I spent 5 minutes searching in DP and found your comment - bingo. Thanks!
     
    Phynder, Jul 28, 2006 IP
  9. emac

    emac Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    chmod to 0777
     
    emac, Jul 30, 2006 IP
  10. Phynder

    Phynder Well-Known Member

    Messages:
    2,603
    Likes Received:
    145
    Best Answers:
    0
    Trophy Points:
    178
    #10
    Yeah - that isn't the problem. It is related the the firewall. So, if my host is blocking fopen - it doesn't matter how many files I modify - it is still blocked at a level I cannot influence.
     
    Phynder, Jul 30, 2006 IP
  11. Old Welsh Guy

    Old Welsh Guy Notable Member

    Messages:
    2,699
    Likes Received:
    291
    Best Answers:
    0
    Trophy Points:
    205
    #11
    I have had to change hosts for many of my sites because they disabled fopen & popen. it is a right shit :(
     
    Old Welsh Guy, Jul 30, 2006 IP
  12. Phynder

    Phynder Well-Known Member

    Messages:
    2,603
    Likes Received:
    145
    Best Answers:
    0
    Trophy Points:
    178
    #12
    Dang - that is what I was afraid of. Thanks for letting me know I am not the only one having this PROBLEM!

    Does this affect people's ability to use the DP Co-op links on their site?
     
    Phynder, Jul 30, 2006 IP
  13. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #13
    My host blocks fopen but I can email them a list of urls to whitelist which works fine for me.
     
    mad4, Jul 31, 2006 IP
  14. Phynder

    Phynder Well-Known Member

    Messages:
    2,603
    Likes Received:
    145
    Best Answers:
    0
    Trophy Points:
    178
    #14
    That is a good idea - maybe I will try and contact one of my hosts and see if they can (I mean "will") this. Thanks!
     
    Phynder, Jul 31, 2006 IP