Скачать файл pdf в приложении phonegap для iOS и Android - PullRequest
0 голосов
/ 27 августа 2018

У меня маленькая ситуация. Я не уверен, почему этот код не работает. Пожалуйста, помогите мне взглянуть на это. Я создаю мобильное приложение со сборкой phonegap и использую файл cordova-plugin-file. Вот мои коды в JavaScript и PHP.

Javascript

var nurlink = 'https://..../appery/downloadCurriculum.php?source=nurs'; // link to switch php program 
//=====================================
function getSampleFileNur(dirEntry) {
statusMsg.innerHTML = 'Nursery: Downloading..';   // div button triggers request for nursery

    var xhr = new XMLHttpRequest();
    xhr.open('GET', nurlink, true);
    xhr.responseType = 'blob';

    xhr.onload = function(){
        if (this.status == 200) {
            var blob = new Blob([this.response], { type: 'application/pdf' });
            saveFile(dirEntry, blob, "curriculum.pdf");
            statusMsg.innerHTML = this.responseText;  
        }
    };
    xhr.send();
}

и PHP

    <?php header('Access-Control-Allow-Origin: *'); ?>
    <?php ob_start(); ?>
    <?php session_start(); ?>
    <?php error_reporting(0); ?>
    <?php #error_reporting(E_NOTICE | E_ALL); ?>
    <?php ini_set('display_errors', 0); ?>

    <?php
    if($_GET['source']){
        $source = $_GET['source'];

    }

    switch($source){

        case 'nursery':
        $file_url = 'https://www.---/curriculum_Jul28_1b640.pdf';
        header('Content-Type: application/pdf');
        header("Content-Transfer-Encoding: Binary"); 
        header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\""); 
        readfile($file_url);
        echo 'Downloading Curriculum for Nursery '.$month.' '.$year2;
        break;

        case 'preteens':
        $file_url = 'https://www..../curriculum_Jul203bad8.pdf';
        header('Content-Type: application/pdf');
        header("Content-Transfer-Encoding: Binary"); 
        header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\""); 
        readfile($file_url);
        echo 'Downloading Curriculum for Preteens '.$month.' '.$year2;
        break;

        default:
            echo 'Download is starting.';
    }
?>

Спасибо, ребята

...