Re: HELP! tempnam(); function confusion
| From: | Pavel Jartsev | Date: | Wed, 05 Jul 2000 15:41:55 +0000 |
| Subject: | Re: HELP! tempnam(); function confusion | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-4984@lists.php.net to get a copy of this message | ||
"C. Marcera" wrote:
>
> ### Why does this code:
>
> $tmpfname = tempnam( "/tmp", "PErq" );
> echo "file made '$tmpfname'<BR>";
> echo "$tmpfname<BR>";
> $tempfile = fopen( "$tmpfname", "w" );
> echo "file open '$tempfile'<BR>";
> $num = count( $query_results );
> for( $i=0; $i<$num; $i++ ) {
> fwrite( "$tempfile",
> "\t<LI<STRONG>$query_results[$i]</STRONG><LI>\r" );
> echo "file written to '$tempfile'<BR>";
> }
> fclose( "$tempfile" );
> echo "file closed '$tempfile'<BR>";
>
> ### produce this:
>
> file made '/tmp/PErq000730'
> /tmp/PErq000730
> file open '16'
> file written to '16'
> file closed '16'
>
> Where is the 16 coming from? when I place a "/" or "/tmp" in the fopen()
> function then it will display the '/tmp/PErq000730', but the path is wrong
> then (i.e. Warning: fopen("/tmp//tmp/PErq000732","w") - No such file or
> directory)
>
> Is there another way to return the filename with tempnam()? Any help would
> be great... thanks in advance!
>
Hi!
tempnam() returns new filename as string, it's not actual file. And this
string (in this case $tmpfname)
you can use as filename for fopen().
fopen() returns file handle ($tempfile) as integer. This is the 16 in
this case.
Maybe this helps.
--
Pavel a.k.a. Papi