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?
What's wrong with this code
Moderator: General Moderators
Re: What's wrong with this code
Try adding the "b" flag to both fopens.
Re: What's wrong with this code
I get this error:
Warning: fputs() expects parameter 2 to be string, resource given in C:\xampp\htdocs\test\index.php on line 5
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
I visited that page a lot of times before, but don't see the solution..
Re: What's wrong with this code
Given that fputs is an alias of fwrite,
The second argument is supposed to be a string. $fr is not a string. You're using the wrong variable.int fwrite ( resource $handle , string $string [, int $length ] )