创建 Amazon Kindle 下载链接
我注意到 Kindle 通过扩展名识别文件类型。因此,我在我的网站上编写了一个小脚本,用于下载文件、添加“.azw”扩展名并提供下载链接。有时它工作得很好,但是...
问题是我不是 PHP 开发人员,我确信脚本不是以最好的方式编写的。问题是该脚本不会下载某些文件(exe),而是加载另一个 exe。它给出一个错误,指出找不到该文件并创建一个长度为 0 的 filename.exe.azw
文件。此问题仅在 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 如果你想测试一下。
I noticed that Kindle recognizes the file types by their extension. So, I wrote a small script on my website that downloads a file, adds ".azw" extension and provide a download link. It works well sometimes but...
The problem is that I'm not a PHP developer and I'm sure the script is not written in the best way. A problem is that the script doesn't download some files (exe) but loads another exe. It gives an error saying that it cannot find the file and creates a filename.exe.azw
file with 0 length. This issue appears only on the Kindle, but on the PC it's ok.
Also it seems that it can download only files smaller than 9 Mb.
The code is here:
<?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;
}
?>
The script is at http://forexsb.com/test/file.php if you want to test it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论