Yii 1.0 Download Zip files

Download Zip Files Using Yii

Here I have added the code to download the Zip files in yii folder.
SourceCode:


public function downloadfinal($docid,$docname)
{
    $filename=Dirdetails"filename.zip"; 
    if(file_exists($filename)){
        $path_parts = pathinfo($filename); 
        $ext = strtolower($path_parts["extension"]); 
        switch ($ext) 
        { 
            case "pdf": $ctype="application/pdf"; break; 
            case "exe": $ctype="application/octet-stream"; break; 
            case "zip": $ctype="application/zip"; break; 
            case "doc": $ctype="application/msword"; break; 
            case "xls": $ctype="application/vnd.ms-excel"; break; 
            case "ppt": $ctype="application/vnd.ms-powerpoint"; break; 
            case "gif": $ctype="image/gif"; break; 
            case "png": $ctype="image/png"; break; 
            case "jpg": $ctype="image/jpg"; break; 
            default: $ctype="application/force-download"; 
        } 
		
        $newpath=$extract.'/'.$filename;    
        header("Pragma: public");
        header("Content-Type: application/$ctype");
        header("Content-Disposition: inline; filename=$docname");
        header('Content-Length: '.filesize($filename));
        header("Accept Ranges: bytes");
        header("Expires: 0"); 
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
        readfile("$filename");
    }
    else{
        echo "error";
    }
}