Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #2974 > unrolled thread
| Started by | "eBob.com" <eBob.com@totallybogus.com> |
|---|---|
| First post | 2011-08-27 20:56 -0400 |
| Last post | 2011-08-28 16:36 +0000 |
| Articles | 7 — 4 participants |
Back to article view | Back to comp.lang.php
fopen error "eBob.com" <eBob.com@totallybogus.com> - 2011-08-27 20:56 -0400
Re: fopen error BKDotCom <kent.brad@gmail.com> - 2011-08-27 20:55 -0700
Re: fopen error "eBob.com" <eBob.com@totallybogus.com> - 2011-08-28 12:00 -0400
Re: fopen error "A" <a@a.a> - 2011-08-28 17:23 +0200
Re: fopen error "eBob.com" <eBob.com@totallybogus.com> - 2011-08-28 12:07 -0400
Re: fopen error "A" <a@a.a> - 2011-08-28 17:27 +0200
Re: fopen error Denis McMahon <denis.m.f.mcmahon@gmail.com> - 2011-08-28 16:36 +0000
| From | "eBob.com" <eBob.com@totallybogus.com> |
|---|---|
| Date | 2011-08-27 20:56 -0400 |
| Subject | fopen error |
| Message-ID | <Hmg6q.167690$7C3.38705@en-nntp-06.dc1.easynews.com> |
This fopen fails and I don't understand why ...
$fpFileOut = fopen($fileout,"c");
if (!$fpFileOut) {echo "Error opening $fileout\n"; echo E-WARNING; exit;}
The file does not exist but shouldn't "c" create it? My understand of "c"
is that it's created if it doesn't exist and overwrites the file if it does
exist. (That's not exactly what the doc says but that is the way I
understand it.)
My attemp to echo E-WARNING produces "0". I have no idea what's up with
that.
Probably a dumb noob error as I am a dumb noob.
Thanks, Bob
[toc] | [next] | [standalone]
| From | BKDotCom <kent.brad@gmail.com> |
|---|---|
| Date | 2011-08-27 20:55 -0700 |
| Message-ID | <781ed9c7-a89d-48eb-bf2b-3aefad6be6bf@b9g2000prd.googlegroups.com> |
| In reply to | #2974 |
On Aug 27, 7:56 pm, "eBob.com" <eBob....@totallybogus.com> wrote:
> This fopen fails and I don't understand why ...
>
> $fpFileOut = fopen($fileout,"c");
> if (!$fpFileOut) {echo "Error opening $fileout\n"; echo E-WARNING; exit;}
>
> The file does not exist but shouldn't "c" create it? My understand of "c"
> is that it's created if it doesn't exist and overwrites the file if it does
> exist. (That's not exactly what the doc says but that is the way I
> understand it.)
Does the directory you're attempting to create the file in exist?
If it does, do you have proper rights to write in it?
Or does the file already exist and you don't have rights to modify it?
> My attemp to echo E-WARNING produces "0". I have no idea what's up with
> that.
"If the open fails, an error of level E_WARNING is generated. You may
use @ to suppress this warning. "
See http://www.php.net/manual/en/book.errorfunc.php
Nutshell E_WARNING is a constant signifying the severity of the error
not a variable describing the last error
To see the actual error open the error log file.
Or
error_reporting(E_ALL ^ E_NOTICE); // report all errors except for
notices
// just in case it's
currently set to to report no errors
ini_set('display_errors',1); // output the error
// (in addition to writing it
to error log)
Or, if you've got PHP >= 5.2, you can try
print_r(error_get_last());
anyhow, once you view see the error, you should know the reason for
the error. :)
[toc] | [prev] | [next] | [standalone]
| From | "eBob.com" <eBob.com@totallybogus.com> |
|---|---|
| Date | 2011-08-28 12:00 -0400 |
| Message-ID | <BBt6q.165042$nZ1.150242@en-nntp-15.dc1.easynews.com> |
| In reply to | #2975 |
Thanks very much BK. Those tips are going to make my debugging much easier.
(Why don't books mention such aids at the outset?)
My mistake was a dumb logic/typo error which tired eyes were unable to see
last night, but which fresh eyes spotted this morning.
Thanks again, Bob
"BKDotCom" <kent.brad@gmail.com> wrote in message
news:781ed9c7-a89d-48eb-bf2b-3aefad6be6bf@b9g2000prd.googlegroups.com...
On Aug 27, 7:56 pm, "eBob.com" <eBob....@totallybogus.com> wrote:
> This fopen fails and I don't understand why ...
>
> $fpFileOut = fopen($fileout,"c");
> if (!$fpFileOut) {echo "Error opening $fileout\n"; echo E-WARNING; exit;}
>
> The file does not exist but shouldn't "c" create it? My understand of "c"
> is that it's created if it doesn't exist and overwrites the file if it
> does
> exist. (That's not exactly what the doc says but that is the way I
> understand it.)
Does the directory you're attempting to create the file in exist?
If it does, do you have proper rights to write in it?
Or does the file already exist and you don't have rights to modify it?
> My attemp to echo E-WARNING produces "0". I have no idea what's up with
> that.
"If the open fails, an error of level E_WARNING is generated. You may
use @ to suppress this warning. "
See http://www.php.net/manual/en/book.errorfunc.php
Nutshell E_WARNING is a constant signifying the severity of the error
not a variable describing the last error
To see the actual error open the error log file.
Or
error_reporting(E_ALL ^ E_NOTICE); // report all errors except for
notices
// just in case it's
currently set to to report no errors
ini_set('display_errors',1); // output the error
// (in addition to writing it
to error log)
Or, if you've got PHP >= 5.2, you can try
print_r(error_get_last());
anyhow, once you view see the error, you should know the reason for
the error. :)
[toc] | [prev] | [next] | [standalone]
| From | "A" <a@a.a> |
|---|---|
| Date | 2011-08-28 17:23 +0200 |
| Message-ID | <j3dml8$3kh$1@gregory.bnet.hr> |
| In reply to | #2974 |
> $fpFileOut = fopen($fileout,"c");
> if (!$fpFileOut) {echo "Error opening $fileout\n"; echo E-WARNING; exit;}
do an echo $fileout; before fopen to see what the folder/file is.
remember the following:
- in linux/unix the filenames are case sensitive and file system is a bit
different than windows
- when you define $fileout remember if you use backslashes you need to
escape them so it is not
$fileout = "c:\folder\file.txt";
rather
$fileout = "c:\\folder\\file.txt";
in php you can use forward slashes instead which don't require escaping:
$fileout = "c:/folder/file.txt";
- you need to have write permissions (755, 666 etc.) if it is unix/linux
system. many hosters set this for PHP but you haven't specified what kind of
host you test this on.
it is probably my lazyness, but unless you really need fopen you can get by
just fine with much easier functions like readfile, file(),
file_get_contents(), file_put_contents()... all work done in a single line
rather than fopen, fread, fwrite, fclose.
[toc] | [prev] | [next] | [standalone]
| From | "eBob.com" <eBob.com@totallybogus.com> |
|---|---|
| Date | 2011-08-28 12:07 -0400 |
| Message-ID | <nIt6q.143833$BZ.114107@en-nntp-03.dc1.easynews.com> |
| In reply to | #2977 |
Thanks A. I was able to find my dumb typo/logic error this morning. Thanks
for making me aware of the file_get_contents and file_put_contents
functions. I like to make my code as concise as possible.
Incidentally ... I am using single backslashes on the (Windows) command line
to specify file names and somehow that seems to be working fine. I'm using
PHP 5.3.
Thanks again,
Bob
"A" <a@a.a> wrote in message news:j3dml8$3kh$1@gregory.bnet.hr...
>> $fpFileOut = fopen($fileout,"c");
>> if (!$fpFileOut) {echo "Error opening $fileout\n"; echo E-WARNING;
>> exit;}
>
> do an echo $fileout; before fopen to see what the folder/file is.
>
> remember the following:
>
> - in linux/unix the filenames are case sensitive and file system is a bit
> different than windows
> - when you define $fileout remember if you use backslashes you need to
> escape them so it is not
> $fileout = "c:\folder\file.txt";
> rather
> $fileout = "c:\\folder\\file.txt";
>
> in php you can use forward slashes instead which don't require escaping:
>
> $fileout = "c:/folder/file.txt";
>
> - you need to have write permissions (755, 666 etc.) if it is unix/linux
> system. many hosters set this for PHP but you haven't specified what kind
> of host you test this on.
>
> it is probably my lazyness, but unless you really need fopen you can get
> by just fine with much easier functions like readfile, file(),
> file_get_contents(), file_put_contents()... all work done in a single line
> rather than fopen, fread, fwrite, fclose.
>
[toc] | [prev] | [next] | [standalone]
| From | "A" <a@a.a> |
|---|---|
| Date | 2011-08-28 17:27 +0200 |
| Message-ID | <j3dmru$3ro$1@gregory.bnet.hr> |
| In reply to | #2974 |
also remember that single and double quotes don't behave the same in php - escapes don't work on single quotes. <?php $abc = "\r\naaa\tbbb"; echo $abc; $abc = '\r\naaa\tbbb'; echo $abc; ?>
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denis.m.f.mcmahon@gmail.com> |
|---|---|
| Date | 2011-08-28 16:36 +0000 |
| Message-ID | <4e5a6e8e$0$2735$a8266bb1@newsreader.readnews.com> |
| In reply to | #2974 |
On Sat, 27 Aug 2011 20:56:44 -0400, eBob.com wrote:
> This fopen fails and I don't understand why ...
>
> $fpFileOut = fopen($fileout,"c");
> if (!$fpFileOut) {echo "Error opening $fileout\n"; echo E-WARNING;
> exit;}
If you're doing this at the command line, you should get an error message
of some sort.
If you're doing it on a web server, it should write an error message
somewhere.
The error message may have more information.
Look on the php documentation website for error handling functions to
obtain the error message if you can't find it anywhere else.
Rgds
Denis McMahon
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web