为亚马逊Kindle创建下载链接

时间:2011-09-06 13:43:58

标签: php download 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

0 个答案:

没有答案