Ask a Question related to PHP Development, Design and Development.
-
Neudeck #1
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
-
#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... -
#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: ... -
Alvaro #2
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
-
Neudeck #3
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
-
Alvaro #4
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
-
yann #5
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
-
Neudeck #6
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



Reply With Quote

