0

I am using a php script to force-download video files of average size 100-150 MB. Now every time i download a file 4KB sized file is getting downloaded. Do i need to do changes in php.ini? Any other change required.

    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);

RESOLVED: at the last two places $myFile was used instead of $myfile. Thanks All. Thanks Pekka the 4kb files were errors had to convert them to html to read them.

codename_subho
  • 291
  • 6
  • 20

2 Answers2

0

Try to eliminate the shorthand notation in the .ini

Duplicate of this: Changing upload_max_filesize on PHP ?

help on it here: http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes

Community
  • 1
  • 1
Phlume
  • 2,813
  • 2
  • 16
  • 37
  • What would be the issue with shorthand notation for sizes? Also this is a download issue, I don't see why it would be a duplicate of an issue that is about uploading files (because `upload_max_filesize` is not related to downloading). – Arjan Dec 30 '13 at 18:00
  • if the upload itself truncates the file wouldn't the download also be serving a truncated file? – Phlume Dec 30 '13 at 18:13
  • That would result in either an empty file or no file at all. – Arjan Dec 31 '13 at 08:07
0

RESOLVED: In the last two places $myFile was used instead of $myfile which caused the error. Thanks All. Thanks Pekka the 4kb files were errors had to convert them to html to read them.

codename_subho
  • 291
  • 6
  • 20