douzhang8840 2010-12-12 23:46
浏览 33
已采纳

使用本机PHP函数在PHP中下载/恢复大文件

I have to implement a simple file download client in PHP capable of downloading large files as well as resuming them.

Is there a way i can download large files (>700 MB) in PHP and still have my PHP memory limit to 128M ? I'm guessing this has to do with writing to a file pointer. Any clue on which file handling functions to use ? there are so many. I am guessing fopen, flock, (fwrite,fgets,fread), fclose. Or should i use cURL ?

How do i resume downloads which are broken ? Script execution timeout, user stopping script, remote server timeout etc. ?

  • 写回答

2条回答 默认 最新

  • dreamworld2007 2010-12-13 01:54
    关注

    This should be possible using cURL by setting the CURLOPT_FILE and CURLOPT_RESUME_FROM options. I'm not sure whether cURL will overwrite the file or append to it, also whether it'll buffer the file in memory or write it straight to disk. You may have to do some tests there.

    If you want more control over the whole process, you can use fsockopen to create a raw connection to the server you're downloading from and write to and read from this connection using the normal fread and fwrite functions. You'd have to send (fwrite) the correct HTTP headers to the connection to initiate the transfer—most importantly the Range header for resuming transfers—and then read a few bytes using fread, then write those to a file and repeat until the transfer is complete.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?