微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用php在服务器之间传输文件

Hello
I wrote a little code in PHP that enables me to download a file from one
 website to my own!
but there is a little problem here!
I can only Download files from my website that are less than 4MB:(
Now my question is that in what way I can Download special 
part of files from other websites!
like from 1st byte to 10th byte!

And second question is how to get file 
information before starting Download!
(I want files size for downloading)

http://www.polarpengi.gigfa.com/code.htm

解决方法:

function downloadFileFromUrl($url, $dstFilepath) {
    $fr = @fopen($url, 'r');
    if($fr === false) {
        throw new Primage_Proxy_Storage_SourceNotFound($url);
    }
    $fw = fopen($dstFilepath, 'w');
    if($fw === false) {
        throw new Exception('Writing to file "' . $dstFilepath . '" Failed');
    }

    $timeLimit = 1000;
    set_time_limit($timeLimit);
    $deadline = time() + 1000;

    while(!feof($fr)) {
        $bufferString = fread($fr, 10000);
        fwrite($fw, $bufferString);
        if($deadline - time() < 10) {
            fclose($fw);
            fclose($fr);
            unlink($dstFilepath);
            throw new Primage_Proxy_Storage_SourceNotFound($url);
        }
    }
    fclose($fw);
    fclose($fr);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐