douyakan8924 2013-12-31 19:31
浏览 67
已采纳

强制下载脚本下载0kb文件

I use this script to download a file but what i get is a 0kb file How can i solve this? The video files have a size of 100MB. Do i need to do any changes in php.ini?

//$myfile = "http://localhost/project/".$_POST['file'];
$myfile='http://localhost/project/upload/WP_20130425_002.mp4';

$temp = explode(".",$myfile);
$ext = strtolower(end($temp));
$mime_types = array(

        // video
        '3gp' => 'video/3gpp',
        '3g2' => 'video/3g2',
        'avi' => 'video/avi',
        'mp4' => 'video/mp4',
        'asf' => 'video/asf',
        'mov' => 'video/quicktime',
    );
if (array_key_exists($ext, $mime_types)){
$mm_type=$mime_types[$ext];
}
else{
$mm_type="application/octet-stream";
}

//header("Cache-Control: public, must-revalidate");
header("Pragma: public");

header("Content-Type: ".$mm_type);

header('Content-Disposition: attachment; filename='.basename($myfile));
header('Content-Length: '.filesize($myfile));
header("Content-Transfer-Encoding: binary");
ob_clean();
flush();
readfile($myfile);

UPDATE: Problem resolved. I removed the full pathname to relative path name and things worked. :)

  • 写回答

1条回答 默认 最新

  • drfm55597 2014-01-03 15:46
    关注

    UPDATE: Problem resolved. I removed the full pathname to relative path name and things worked. :) So instead of :

    $myfile='http://localhost/project/upload/WP_20130425_002.mp4';
    

    I used this:

    $myfile='upload/WP_20130425_002.mp4';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥15 对于这个问题的算法代码
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题