Search

Dec 18, 2015

Back link URL by Javascript


/**
 * Created by kongltn on 12/25/2015.
 */

$(document).ready(function () {
    $("#backButtonInheaderBar").click(function () {
        if (sessionStorage.backURL !== undefined) {
            sessionStorage.backIsClick = 1;
            var curArray = JSON.parse(sessionStorage.backURL);
            if (curArray.length > 1) curArray.pop();
            sessionStorage.backURL = JSON.stringify(curArray);
            window.location.replace(curArray[curArray.length - 1]);
        }
    });

    if (!sessionStorage.backURL || sessionStorage.backURL === undefined) {
        sessionStorage.backURL = JSON.stringify([window.location.origin]);
    }

    var curUrlHref = window.location.href;
    if (sessionStorage.backIsClick && sessionStorage.backIsClick === "1") {
        sessionStorage.backIsClick = 0;
    } else {
        var urlArray = JSON.parse(sessionStorage.backURL);
        if (curUrlHref != urlArray[urlArray.length - 1]) {
            urlArray.push(curUrlHref);
        }
        sessionStorage.backURL = JSON.stringify(urlArray);
    }

    //console.log(sessionStorage.backURL);
    //console.log(sessionStorage.backIsClick);
});

Dec 16, 2015

Action download file in PHP


/**
 * Action Download file
 * @return undefined
 */
public function actionDownload()
{
    $file = Yii::app()->request->getParam('file');
    $modelArchives = Archives::model()->find('path=:path', array(':path' => $file));
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-type:application/octet-stream");
    header('Content-Disposition: attachment; filename="' . $modelArchives->fileName . '"');
    $contentArchive = Yii::getPathOfAlias('webroot') . Yii::app()->params["archiveFolderPath"] . '/' . $file;
    echo file_get_contents($contentArchive);
    exit;
}