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

时间:2013-12-31 19:31:55

标签: php

我使用此脚本下载文件,但我得到的是0kb文件 我怎么解决这个问题?视频文件的大小为100MB。我需要在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);

更新:问题已解决。我删除了相对路径名的完整路径名,并且工作正常。 :)

1 个答案:

答案 0 :(得分:1)

更新:问题已解决。我删除了相对路径名的完整路径名,并且工作正常。 :) 所以而不是:

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

我用过这个:

$myfile='upload/WP_20130425_002.mp4';