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.

fopen is not working please help

Discussion in 'PHP' started by shino, Apr 18, 2006.

  1. #1
    Dear friends,

    Iam newbe to this forum. I am a php developer. But now I am working with files.

    I am using fopen("file.txt","r");

    This is not working for me. The safe mode is on. and open_basedir is not set

    and I tried with the "file_exists" command to check if the file is there or not , That is working fine and file exists.

    But I am not able to open that file for reading


    Pleae help me

    Thanks in advance

    Shino
     
    shino, Apr 18, 2006 IP
  2. alext

    alext Active Member

    Messages:
    406
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    68
    #2
    Have you checked the file permissions on the file you are trying to read? Getting any error messages or notices?

     
    alext, Apr 18, 2006 IP
  3. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Have you tried the is_readable function? That should tell you if you can open for reading or not. Also, what error does it print when you try to open the file. What version of PHP are you using and on what OS?
     
    exam, Apr 18, 2006 IP
  4. dotcomsdotbiz

    dotcomsdotbiz Banned

    Messages:
    73
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ssh in and chmod 755 the file you are trying to open. You can verify permissions by typing ls -l filename

    mike :)
     
    dotcomsdotbiz, Apr 18, 2006 IP
  5. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #5
    All of the above applies. Plus, all you have said is it's not working for you. Without seeing the real code, we may never know if the problem lies therein.
     
    noppid, Apr 18, 2006 IP
  6. shino

    shino Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    $file = "./test.txt";

    if(is_readable($file))
    {
    echo "readable";
    }
    else
    {
    echo "not readable";
    }
    if($fp = fopen($file,"r"))
    {
    while ($data = fread($fp,4096))
    {
    echo "-----".$data;
    }
    }


    This is the code I am uning
    and is_readable is telling readable

    But file is not opening

    I am using windows OS



    Thanks
    shino
     
    shino, Apr 18, 2006 IP
  7. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It works for me, but you might try calling clearstatcache(); at the top.
     
    exam, Apr 19, 2006 IP
  8. shino

    shino Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    No I am not using something like that
     
    shino, Apr 20, 2006 IP
  9. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #9
    Have you tried without the ./ infront of the file name? Or perhaps try the absolute path to the file? (ie c:/mydir/myfile )

    Also, try the b flag. fopen($file,"rb").
     
    noppid, Apr 20, 2006 IP
  10. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #10
    When I tested it, I tested absolute path, relative path, and with the ./ and all three worked for me, so I think his problem is elsewhere. Shino, try calling clearstatcache before your code and see what happens.
     
    exam, Apr 22, 2006 IP
  11. shino

    shino Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    file_get_contents command is working for me

    I tried like this too;


    clearstatcache();
    $fp = fopen("text.txt","rb") or die("No Ya");
    echo "Opened ";

    but the same result

    It is godaddy server. and is windows system.
     
    shino, Apr 24, 2006 IP
  12. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #12
    You might want to ask Godaddy's tech support.
     
    exam, Apr 24, 2006 IP