I'm searching a method to convert a torrent encoding (from UTF-8-BOM to WINDOWS-1252) before download because if I download it simply with readfile() the torrent is not valid bencoding, so I need to convert it to WINDOWS-1252 or CP1252.
Click Download on my page, and download the torrent file encoded in WINDOWS-1252.
This is my script:
header("Content-Disposition: attachment; filename=\"$tname.torrent\"");
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($fn));
$content = iconv("UTF-8", "WINDOWS-1252", readfile($fn));
print($content);
Acually, this script is not working because when I download the file, it's empty. What to do?
readfile
prints the requested file directly, but you're using it like it would return the file's contents.
For that you'll have to use file_get_contents
.
You might also get the wrong file size, because a file encoded in UTF-8 might very well have a different size than one encoded in Windows-1252.
So instead of filesize($fn)
, use strlen($content)
.