codename_subho
codename_subho

Reputation: 476

force download script downloads 0kb file

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. :)

Upvotes: 0

Views: 818

Answers (1)

codename_subho
codename_subho

Reputation: 476

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

Upvotes: 1

Related Questions