<?php
ini_set('display_errors', TRUE);
error_reporting(E_ALL);
$curBookFolder = $_POST['curBookFolder'];
$curBookFolderOPS = $_POST['curBookFolderOPS'];
$curBookTempFolder = $_POST['curBookTempFolder'];
var_dump($_POST);
mkdir($curBookTempFolder);
chmod($curBookTempFolder, 0777);
$dir=$curBookFolder.'/';
$dirNew=$curBookTempFolder;
$zipFile = $curBookTempFolder . 'book.zip';
$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)) {
continue;
}
if (is_dir($file)) {
//$zip->addEmptyDir(str_replace("$dir", '', "$file/"));
} elseif (is_file($file)) {
$zip->addFromString(
str_replace("$dir", '', $file),
file_get_contents($file)
);
}
}
$zip->close();
rename($zipFile, $epubFile);
header("Content-type: application/epub+zip");
header("Content-disposition:attachment;filename=".basename($epubFile));
header("Content-Transfer-Encoding: binary");
readfile($epubFile);
?>
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.
ASKER
ASKER
system('zip -q0Xj $filename $mimetype');
I think above code not responded in Zip Archive. So how to solve this issue. Please help?
ASKER
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY