如何以php的大小下载文件

发布于 2025-01-20 20:34:41 字数 829 浏览 2 评论 0原文

我应该在本地PC驱动器中下载带有200MB的大文件视频。

该代码对于中等大小是正确的,但大尺寸失败,返回err_invalid_response。

我也尝试使用readfile和file_get_contents方法,而无需成功。

我的代码php是:

<?php
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=a.mp4");
Header("Content-Description: Download Manager");
header('Content-Transfer-Encoding: binary');
Header("Pragma: No-Cache");
Header("Expires: 0");
ob_clean();
$path="http://myurlexample/...../a.mp4"
$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $path);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    if(curl_exec($ch) === FALSE) {
         echo "Error: " . curl_error($ch);
    } else {
         echo curl_exec($ch);
    }

    curl_close($ch);
flush();
exit();
?>

I should download Big file video with size 200mb in local pc drive.

The code is correct for medium size but fail with big size with return ERR_INVALID_RESPONSE.

I have tried also with readfile and file_get_contents method without succesfull.

My code php is:

<?php
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=a.mp4");
Header("Content-Description: Download Manager");
header('Content-Transfer-Encoding: binary');
Header("Pragma: No-Cache");
Header("Expires: 0");
ob_clean();
$path="http://myurlexample/...../a.mp4"
$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $path);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    if(curl_exec($ch) === FALSE) {
         echo "Error: " . curl_error($ch);
    } else {
         echo curl_exec($ch);
    }

    curl_close($ch);
flush();
exit();
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文