download() public method

Let the client download the file. Warning! No data should be outputted before or after.
public download ( string $name )
$name string Name used for download, usually "title.mobi"
Beispiel #1
0
        for ($i = 0, $lenI = rand(10, 15); $i < $lenI; $i++) {
            $content->appendChapterTitle($i + 1 . ". Chapter " . ($i + 1));
            for ($j = 0, $lenJ = rand(20, 40); $j < $lenJ; $j++) {
                $content->appendParagraph("P" . ($i + 1) . "." . ($j + 1) . " TEXT TEXT TEXT");
            }
            $content->appendPageBreak();
        }
        $mobi->setContentProvider($content);
        //Get title and make it a 12 character long filename
        $title = $mobi->getTitle();
        if ($title === false) {
            $title = "file";
        }
        $title = urlencode(str_replace(" ", "_", strtolower(substr($title, 0, 12))));
        //Send the mobi file as download
        $mobi->download($title . ".mobi");
        die;
    }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Sample</title>
	</head>
	<body>
		<a href='index.php?download'>Download</a>
	</body>
</html>
Beispiel #2
0
        for ($i = 0, $lenI = rand(10, 15); $i < $lenI; ++$i) {
            $content->appendChapterTitle($i + 1 . '. Chapter ' . ($i + 1));
            for ($j = 0, $lenJ = rand(20, 40); $j < $lenJ; ++$j) {
                $content->appendParagraph('P' . ($i + 1) . '.' . ($j + 1) . ' TEXT TEXT TEXT');
            }
            $content->appendPageBreak();
        }
        $mobi->setContentProvider($content);
        //Get title and make it a 12 character long filename
        $title = $mobi->getTitle();
        if ($title === false) {
            $title = 'file';
        }
        $title = urlencode(str_replace(' ', '_', strtolower(substr($title, 0, 12))));
        //Send the mobi file as download
        $mobi->download($title . '.mobi');
        die;
    }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Sample</title>
	</head>
	<body>
		<a href='index.php?download'>Download</a>
	</body>
</html>
 /**
  * MOBI Class
  * @author Sander Kromwijk
  */
 public function produceMobi()
 {
     try {
         Tools::logm('Starting to produce Mobi file');
         $mobi = new MOBI();
         $content = new MOBIFile();
         $messages = new Messages();
         // for later
         Tools::logm('Filling metadata for Mobi...');
         $content->set("title", $this->bookTitle);
         $content->set("author", $this->author);
         $content->set("subject", $this->bookTitle);
         # introduction
         $content->appendParagraph('<div style="text-align:center;" ><p>' . _('Produced by wallabag with PHPMobi') . '</p><p>' . _('Please open <a href="https://github.com/wallabag/wallabag/issues" >an issue</a> if you have trouble with the display of this E-Book on your device.') . '</p></div>');
         $content->appendImage(imagecreatefrompng("themes/_global/img/appicon/apple-touch-icon-152.png"));
         $content->appendPageBreak();
         Tools::logm('Adding actual content...');
         foreach ($this->entries as $item) {
             $content->appendChapterTitle($item['title']);
             $content->appendParagraph($item['content']);
             $content->appendPageBreak();
         }
         $mobi->setContentProvider($content);
         // the browser inside Kindle Devices doesn't likes special caracters either, we limit to A-z/0-9
         $this->bookFileName = preg_replace('/[^A-Za-z0-9\\-]/', '', $this->bookFileName);
         // we offer file to download
         $mobi->download($this->bookFileName . '.mobi');
         Tools::logm('Mobi file produced');
     } catch (Exception $e) {
         Tools::logm('PHPMobi has encountered an error : ' . $e->getMessage());
         $this->wallabag->messages->add('e', $e->getMessage());
     }
 }