Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Drag and drop only takes one object at a time
  • Loading branch information
danielw1990 authored Nov 29, 2024
1 parent 84099de commit 07d6a91
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
41 changes: 41 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
function recurse_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}

function create_uuid()
{
#29eeddc3-4149-4249-b053-d7d3f046802a
#758e65c5-30d7-4a11-9b09-8fbff26ad763
$index = 0;
$hex[$index] = bin2hex(random_bytes(4)) ."-";
$index++;
$hex[$index] = bin2hex(random_bytes(2)) ."-";
$index++;
$hex[$index] = bin2hex(random_bytes(2)) ."-";
$index++;
$hex[$index] = bin2hex(random_bytes(2)) ."-";
$index++;
$hex[$index] = bin2hex(random_bytes(6));

$uuid = "";
for($i = 0;$i <= $index;$i++)
{
$uuid .= $hex[$i];
}

return $uuid;
}
?>
59 changes: 59 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
require_once("functions.php");

$book_title = "test";
$infiles_folder = scandir($book_title);

$infiles = array();
foreach($infiles_folder as $infile)
{
if($infile != "." && $infile != "..")
{
$infiles[] = $infile;
}
}

$basefiles_folder = "basefiles/";
$book_uuid = create_uuid();


$epub_name = $book_title;
$extenension = ".epub";


//create all static stuff
$epub_name .= $extenension;
mkdir($epub_name);

$basefiles[] = "cover.jpeg";
$basefiles[] = "mimetype";
$basefiles[] = "page_styles.css";
$basefiles[] = "stylesheet.css";
$basefiles[] = "titlepage.xhtml";
foreach($basefiles as $basefile)
{
copy($basefiles_folder.$basefile, $epub_name."/".$basefile);
}

recurse_copy($basefiles_folder."META-INF", $epub_name."/META-INF");

//copy the images
$page_number = 1;
foreach($infiles as $infile)
{
copy($book_title."/".$infile, $epub_name."/".$page_number.".jpg");
$page_number++;
}
$pages = $page_number;

//dynamic files
$book_uuid = create_uuid();
require_once($basefiles_folder."content.opf.php");
require_once($basefiles_folder."page_n.xhtml.php");
for($i = 1;$i <= $pages;$i++)
{
write_page_xhtml($i);
}

require_once($basefiles_folder."toc.nx.php");
?>

0 comments on commit 07d6a91

Please sign in to comment.