Page 1 of 1
What's wrong with this code
Posted: Sat Apr 24, 2010 3:20 pm
by alexvorn2
please help to write binary data to a file:
I use this code but no work:
<?php
$fr = fopen('wtf.png', 'r');
$fr2 = fopen('wtf2.png', 'w');
$data = fread($fr, 299052);
fputs($fr2, $fr, 299052);
fclose($fr);
?>
Can you please tell me what's the problem with the code?
Re: What's wrong with this code
Posted: Sat Apr 24, 2010 3:46 pm
by requinix
Try adding the "b" flag to both fopens.
Re: What's wrong with this code
Posted: Sat Apr 24, 2010 4:19 pm
by alexvorn2
I get this error:
Warning: fputs() expects parameter 2 to be string, resource given in C:\xampp\htdocs\test\index.php on line 5
Re: What's wrong with this code
Posted: Sat Apr 24, 2010 6:03 pm
by requinix
Re: What's wrong with this code
Posted: Sun Apr 25, 2010 3:34 am
by alexvorn2
I visited that page a lot of times before, but don't see the solution..
Re: What's wrong with this code
Posted: Sun Apr 25, 2010 5:13 am
by requinix
Given that fputs is an alias of fwrite,
int fwrite ( resource $handle , string $string [, int $length ] )
The second argument is supposed to be a string. $fr is not a string. You're using the wrong variable.