(Hint: Use the PHP bbcode tag so we can read your code easier)
$i=fwrite($fd,$str,sizeof($str));
$content=fread($fd,sizeof($filename));
Check out line one. You're writing data. The data goes to the file and moves the file pointer to the end of where it wrote your data. PHP is expecting to write more data so its in a position to do so (to make things go fast). Then on the 2nd line, you're asking PHP to read from the current file pointer what's left of the file, which is nothing, since the file pointer is already at the end of the file.
You might look into using rewind or one of the other filesystem functions to move the pointer to where you want it.