Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default fclose

    Hello,
    I have these lines:
    $fp = "test.txt";
    if ($datei = fopen ($fp, "r")) {
    while (!feof ($datei)) {
    $zeichen = fgetc ($datei);
    echo ($zeichen);
    }
    fclose($fp);
    }

    The file is opened correctly and the content of the file is shown. But
    below the content there is the error:
    Warning: fclose(): supplied argument is not a valid stream resource in
    ........... on line 9
    Where is the mistake?
    Thanks Werner

    Neudeck Guest

  2. Similar Questions and Discussions

    1. #40291 [NEW]: glibc detected - double free or corruption - on fclose for socket
      From: razzul69 at yahoo dot com Operating system: Fedora Core 6 PHP version: 5.2.0 PHP Bug Type: Scripting Engine problem...
    2. #17964 [Com]: socket fclose CLOSE_WAIT
      ID: 17964 Comment by: n-a at mail dot com Reported By: filippo at zirak dot it Status: No Feedback Bug Type: ...
  3. #2

    Default Re: fclose

    *** Neudeck Werner wrote/escribió (Thu, 28 Oct 2004 13:17:01 +0200): 
    [...] 
     

    The error is that $fp is not a valid stream resource. Actually, $fp is a string. Let's check the manual:

    Usage: resource fopen ( string filename, string mode [, int use_include_path [, resource zcontext]] )
    Purpose: Opens file or URL

    Usage: bool fclose ( resource handle )
    Purpose: Closes an open file pointer

    So fclose() doesn't expect a string as an argument. Can you see now where to get a resouce handle from?

    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- Thank you for not e-mailing me your questions
    --
    Alvaro Guest

  4. #3

    Default Re: fclose

    Hello,

    "Alvaro G Vicario" <com>
    schrieb im Newsbeitrag
    news:kym8ry84ek04.k98h53kwusdt$net... 
    > [...] 

    >
    > The error is that $fp is not a valid stream resource. Actually, $fp
    > is a string. Let's check the manual:
    >
    > Usage: resource fopen ( string filename, string mode [, int
    > use_include_path [, resource zcontext]] )
    > Purpose: Opens file or URL
    >
    > Usage: bool fclose ( resource handle )
    > Purpose: Closes an open file pointer
    >
    > So fclose() doesn't expect a string as an argument. Can you see now
    > where to get a resouce handle from?
    >[/ref]
    first: I'm a beginner so I have taken the example out of a book and
    there it was written exactly like above.
    Now I have modified it, like you said and it works.
    Thanks, Werner

    Neudeck Guest

  5. #4

    Default Re: fclose

    *** Neudeck Werner wrote/escribió (Thu, 28 Oct 2004 14:05:02 +0200): 

    For some reason all programming books have typos in basic examples :)

    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- Thank you for not e-mailing me your questions
    --
    Alvaro Guest

  6. #5

    Default Re: fclose

    of course, this does'nt work because fclose wait the handle of the file open
    with fopen !
    if ($datei = fopen ($fp, "r")) this is wrong.....
    $datei is the handle of the open file...
    $handle=fopen ($fp, "r");
    ....... work on file
    fclose($handle);

    yann.


    "Neudeck Werner" <de> a écrit dans le message de news:
    clqnh5$1b5$news.aol.com... 
    >> [...] 
    >> 
    >>
    >> The error is that $fp is not a valid stream resource. Actually, $fp is a
    >> string. Let's check the manual:
    >>
    >> Usage: resource fopen ( string filename, string mode [, int
    >> use_include_path [, resource zcontext]] )
    >> Purpose: Opens file or URL
    >>
    >> Usage: bool fclose ( resource handle )
    >> Purpose: Closes an open file pointer
    >>
    >> So fclose() doesn't expect a string as an argument. Can you see now where
    >> to get a resouce handle from?
    >>[/ref]
    > first: I'm a beginner so I have taken the example out of a book and there
    > it was written exactly like above.
    > Now I have modified it, like you said and it works.
    > Thanks, Werner[/ref]


    yann Guest

  7. #6

    Default Re: fclose

    Hello yann,

    "yann kloniecki" <fr> schrieb im Newsbeitrag
    news:41811cec$0$15755$club-internet.fr... [/ref]
    ........... [/ref][/ref]
    ...........

    in the meantime I have understood it completeley, thanks to you and
    Alvaro.
    After reading your postings and studying the manual, everything works.
    I only wonder, why there is such an example in a book for beginners.
    And in the meantime I have realized, that it's not the only mistake in
    this book (the name ist "PHP4 for dummies")
    Thanks to all
    Werner

    Neudeck Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139