troubleshooting Question

Downloading epub file from server using php

Avatar of JohnLourdu
JohnLourduFlag for Afghanistan asked on
Web Languages and StandardsPHPWeb Components
8 Comments1 Solution1487 ViewsLast Modified:
I have created php script as mentioned below for dynamic downloading of epub files:
ini_set('display_errors', TRUE);

$curBookFolder = $_POST['curBookFolder'];
$curBookFolderOPS = $_POST['curBookFolderOPS'];
$curBookTempFolder = $_POST['curBookTempFolder'];


chmod($curBookTempFolder, 0777);

$zipFile = $curBookTempFolder . '';
$epubFile = $curBookTempFolder . 'book.epub';
$mimetype = 'epub_content/model/mimetype';

$excludes = array('.DS_Store', 'iTunesMetadata.plist');

system('zip -q0Xj $epubFile $mimetype');

$zip = new ZipArchive();
    if ($zip->open($zipFile, ZipArchive::CREATE) != true) {
        throw new Exception("Unable open archive '$zipFile'");

$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::SELF_FIRST);

foreach ($files as $file) {
        if (in_array(basename($file), $excludes)) {
        if (is_dir($file)) {
            //$zip->addEmptyDir(str_replace("$dir", '', "$file/"));
        } elseif (is_file($file)) {
                str_replace("$dir", '', $file),

    rename($zipFile, $epubFile);
    header("Content-type: application/epub+zip");
    header("Content-Transfer-Encoding: binary");

Before rename, the zip file downloaded and extracted fine. But I have renamed zip to epub and download using above script, EPUB file not opened. I have received 'The Compressed(zipped) Folder ... is invalid. Please advice how to solve this.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros