完整文件无法下载

时间:2013-12-30 17:33:45

标签: php

我正在使用php脚本强制下载平均大小为100-150 MB的视频文件。现在,每次下载文件时都会下载4KB大小的文件。我需要在php.ini中做更改吗?需要进行任何其他更改。

    Current php.ini config:
    upload_max_filesize = 400M
    post_max_size=500M
    default_socket_timeout = 60000
    output_buffering= On
    max_execution_time = 5000  
    max_input_time = 5000
    memory_limit = 1000M


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

// Add bellow code for mime type
$ext=strtolower(substr($fl,strrpos($myFile,".")));
$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("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(); 

readfile($myFile);

解决: 在最后两个地方使用$ myFile而不是$ myfile。谢谢大家。感谢Pekka 4kb文件是错误必须将它们转换为HTML来阅读它们。

2 个答案:

答案 0 :(得分:0)

尝试消除.ini

中的简写表示法

重复:Changing upload_max_filesize on PHP

在此处提供帮助:http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes

答案 1 :(得分:0)

已解决:在最后两个地方使用$ myFile而不是$ myfile导致错误。谢谢大家。感谢Pekka 4kb文件的错误必须将它们转换为html才能读取它们。