Back to PhocacartDownload class

Method downloadContent

public static
downloadContent
(mixed $content, mixed $prefix = '', mixed $suffix = '', mixed $forceName = '', mixed $forceMimeType = '')

Method downloadContent - Source code

public static function downloadContent($content, $prefix = '', $suffix = '', $forceName = '', $forceMimeType = '')
{
    $pC = PhocacartUtils::getComponentParameters();
    $import_export_type = $pC->get('import_export_type', 0);
    if ($import_export_type == 0) {
        $mimeType = 'text/csv';
        $name = "phocacartproductexport.csv";
    } else {
        $mimeType = 'application/xml';
        $name = "phocacartproductexport.xml";
    }
    if ($forceName != '') {
        $name = $forceName;
    }
    if ($forceMimeType != '') {
        $mimeType = $forceMimeType;
    }
    $content = $prefix . $content . $suffix;
    // Clean the output buffer
    ob_end_clean();
    // test for protocol and set the appropriate headers
    jimport('joomla.environment.uri');
    $_tmp_uri = Uri::getInstance(Uri::current());
    $_tmp_protocol = $_tmp_uri->getScheme();
    if ($_tmp_protocol == "https") {
        // SSL Support
        header('Cache-Control: private, max-age=0, must-revalidate, no-store');
    } else {
        header("Cache-Control: public, must-revalidate");
        header('Cache-Control: pre-check=0, post-check=0, max-age=0');
        header("Pragma: no-cache");
        header("Expires: 0");
    }
    /* end if protocol https */
    header("Content-Description: File Transfer");
    header("Expires: Sat, 30 Dec 1990 07:07:07 GMT");
    header("Accept-Ranges: bytes");
    header('Content-Encoding: UTF-8');
    header("Content-Type: " . (string) $mimeType . '; charset=UTF-8');
    header('Content-Disposition: attachment; filename="' . $name . '"');
    header("Content-Transfer-Encoding: binary\n");
    echo "";
    // UTF-8 BOM
    echo $content;
    flush();
    return true;
    //exit;
}