我注意到 Kindle 通过扩展名识别文件类型。因此,我在我的网站上编写了一个小脚本,用于下载文件、添加“.azw”扩展名并提供下载链接。有时效果很好,但是...
问题是我不是 PHP 开发人员,而且我确信脚本不是以最好的方式编写的。一个问题是脚本不会下载一些文件(exe)而是加载另一个exe。它给出一个错误,说它找不到文件并创建一个filename.exe.azw
长度为 0 的文件。此问题仅出现在 Kindle 上,但在 PC 上没问题。
此外,它似乎只能下载小于 9 Mb 的文件。
代码在这里:
<?php
if(!isset($_POST['link'])) {
?>
<form method="post" action="file.php">
<p>
Enter link: http://
<input type="text" name="link" size="20"/>
<input type="submit" name="submit" value="submit" />
</p>
</form>
<?php
} else {
$remote = 'http://' . $_POST['link'];
$download = download($remote);
echo 'Download: <a href="' . $download . '">' . $download . '</a>';
}
function download($url) {
$lastDashPos = strrpos($url, '/');
$local = substr($url, $lastDashPos + 1, strlen($url) - $lastDashPos) . '.azw';
$handle = file_get_contents($url);
file_put_contents($local, $handle);
return $local;
}
?>
如果您想对其进行测试,该脚本位于http://forexsb.com/test/file.php 。