#22177 [Opn->Bgs]: Warning: fopen() expects parameter 1 to be string
| From: | nicos@php.net | Date: | Tue, 11 Feb 2003 21:59:24 +0000 |
| Subject: | #22177 [Opn->Bgs]: Warning: fopen() expects parameter 1 to be string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-32825@lists.php.net to get a copy of this message | ||
ID: 22177
Updated by: nicos@php.net
Reported By: laudanp@yahoo.com
-Status: Open
+Status: Bogus
Bug Type: Filesystem function related
Operating System: RedHat
PHP Version: 4.3.0
New Comment:
As Jani said, tmpfile returns a resource, no need to try to fopen it.
He said also that nothing was changed in 4.3.0 about it, which is
right. Your code is bogus and I don't think it ever worked.
See: http://www.php.net/manual/en/function.tmpfile.php
resource tmpfile ( void)
Creates a temporary file with an unique name in write mode, returning a
file handle similar to the one returned by fopen(). The file is
automatically removed when closed (using fclose()), or when the script
ends.
You should use:
$temp = tmpfile();
fwrite($temp, "writing to tempfile");
fclose($temp); // this removes the file
Not a bug->Bogus again.
Previous Comments:
------------------------------------------------------------------------
[2003-02-11 15:52:09] laudanp@yahoo.com
Per me previous comment addition, the code was not changed whatsoever.
I'm "re-opening" this bug report in the hopes it will gather a
response.
------------------------------------------------------------------------
[2003-02-11 15:50:52] laudanp@yahoo.com
I don't appreciate the RTFM remark, but I am glad you replied back. I
use the php manual extensively but have not seen that particular link.
I can tell you honestly that your doubt is just that, because that same
exact code block worked 100% under php 4.2.3. After the upgrade to 4.3
that code no longer works and it has *not* been changed.
------------------------------------------------------------------------
[2003-02-11 15:48:18] sniper@php.net
RTFM: http://www.php.net/manual/en/function.tmpfile.php
tmpfile() returns a file handle already..NOT filename.
I doubt this ever worked for you as this was not changed in
4.3.0...(you propably used tempnam() instead before)
------------------------------------------------------------------------
[2003-02-11 15:39:40] laudanp@yahoo.com
A php script I have worked fine under PHP 4.2.3, but after the upgrade
to PHP 4.3 whenever I try running it I get these errors:
Warning: fopen() expects parameter 1 to be string, resource in ... on
line 353
Warning: fwrite(): supplied argument is not a valid stream resource in
... on line 354
Warning: fclose(): supplied argument is not a valid stream resource in
... on line 355
Warning: getimagesize(Resource id #4) [function.getimagesize]: failed
to create stream: No such file or directory in ... on line 361
The following blocks of code surround the problematic lines from
above:
if ($input = fopen($image, "rb")) {
$image_data = fread ($input, 2048576);
fclose($input);
if (!$tmp_image = @tmpfile()) {
exit("Cannot create tempfile using
tmpfile().");
}
353: $output = fopen($tmp_image, "wb");
354: fwrite($output, $image_data);
355: fclose($output);
356: } else {
357: exit("Cannot access ".$image." for reading. (Does
not exist or has wrong permissions)");
358: }
359:
360: // Create Image from file by type, get and set size
361: list($width,$height,$type) = getimagesize($tmp_image);
362:
I'm having difficulty determining what the problem is since the code
worked with PHP 4.2.3.
Thanks for your help.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=22177&edit=1