kiwilan / php-ebook Goto Github PK
View Code? Open in Web Editor NEWPHP package to read metadata and extract covers from eBooks, comics and audiobooks.
License: MIT License
PHP package to read metadata and extract covers from eBooks, comics and audiobooks.
License: MIT License
Hello!
First of all, thanks for this great library!
I'm having an issue when an archive is a "badFile". Currently, the error is caught in Ebook.php
, but it is only logged and the script continues.
Later on, the *Metadata.php
files, use the getArchive()->xx
method, and since the archive is null, the error is thrown. Since it's an error and not an Exception, the execution stops.
I can provide a PR for this, I would just like your preferred method of fixing it.
getArchive()
and typhint it as not nullable but I don't have enough visibility on the rest of the code to see if it's a good solution.Epub::check($path)
to check a file before trying to read itThanks!
Try to read a bad archive :)
2.0.12
8.2
Linux
No response
`
public function upload(Request $request)
{
$request->validate([
'epub_file' => 'required|mimes:epub'
]);
$filename = 'eb_' . uniqid() . '.epub';
$path = $request->file('epub_file')->storeAs('epubs', $filename);
$ebook = Ebook::read(storage_path('app/' . $path));
// Access metadata and properties of the eBook
$title = $ebook->getTitle();
$author = $ebook->getAuthorMain();
$description = $ebook->getDescription() ?? 'No Description added';
$coverImage = $ebook->getCover();
// Store cover image
$coverPath = null;
if ($coverImage) {
$coverFilename = 'cover_' . uniqid() . '.png'; // Assuming cover image format is PNG
$coverContents = $coverImage->getContents();
$fullPath = 'covers/' . $coverFilename;
Storage::put($fullPath, $coverContents);
$coverPath = $fullPath; // Store the full path including 'storage/app'
}
// Create a new book
$book = Book::create([
'name' => $title,
'author' => $author,
'isbn' => null,
'book_cover' => $coverPath,
'description' => $description
]);
// Get chapters from the EPUB
$epub = $ebook->getParser()?->getEpub();
$chapters = $epub->getChapters(); // Ensure this line is correctly retrieving chapters
dd($chapters); // Debug to check if chapters are now correctly retrieved
// Save chapters to database
foreach ($chapters as $index => $chapter) {
Chapter::create([
'title' => $chapter->label(), // Use label() method to get the chapter label
'content' => $chapter->content(), // Use content() method to get the chapter content
'book_id' => $book->id,
'src' => $chapter->source(), // Use source() method to get the chapter source
]);
}
return redirect()->route('books.index')->with('success', 'Book uploaded successfully. File name: ' . $filename);
}
`
Upon attempting to upload an EPUB file through the upload function, the process completes successfully without any errors reported. However, upon inspection, it's found that no chapters are created in the database despite the EPUB containing multiple chapters.
Expected Behavior:
After the file is uploaded, the function should extract chapters from the EPUB file and save them to the database. These chapters should be retrievable and displayed for the user.
Actual Behavior:
After uploading an EPUB file, the function successfully creates a book entry in the database with the correct title, author, cover image, and description. However, no chapters are created or saved in the database, even though the EPUB contains multiple chapters.
Debugging Steps Undertaken:
Checked the $chapters variable after retrieving it from the EPUB file. Used dd($chapters) to ensure that chapters are correctly retrieved. However, the dump shows an empty array, indicating that no chapters are being extracted.
Verified that the EPUB file contains multiple chapters by manually inspecting the file using EPUB reader software.
2.3.8
8.2
Windows
No response
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.