-
-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Describe the bug
EPUB import always fails with "Invalid EPUB file" regardless of the file uploaded, making the EPUB import feature completely non-functional.
To Reproduce
- Go to Import EPUB page (
/book/import) - Select a valid EPUB file
- Select a language
- Click Import
- See "Invalid EPUB file" error
Expected behavior
The EPUB file is parsed and imported successfully as a book with chapters.
Screenshots
N/A
Server (please complete)
- LWT version: 3.0.0
- PHP: 8.4.19
- Web server: Apache 2.4.66 (Docker)
- OS: Ubuntu 24.04.3 Live Server (amd64)
Desktop (if necessary):
- Running on Ubuntu server
Additional context
The root cause is in EpubParserService::isValidEpub(). It validates the file extension of the uploaded file's temporary path ($_FILES['thefile']['tmp_name']) rather than the original filename ($_FILES['thefile']['name']). PHP stores uploaded files in a system temp directory with names like /tmp/phpXXXXXX which have no extension, so the extension check always fails and returns false before the file is ever read.
// isValidEpub() receives the tmp_name path e.g. /tmp/phpXXXXXX
$extension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
if ($extension !== 'epub') {
return false; // always fails - temp files have no extension
}Suggested fix: Pass the original filename to isValidEpub() for the extension check while keeping the temp path for the magic byte check:
public function isValidEpub(string $filePath, string $originalName = ''): bool
{
$nameToCheck = $originalName !== '' ? $originalName : $filePath;
$extension = strtolower(pathinfo($nameToCheck, PATHINFO_EXTENSION));
if ($extension !== 'epub') {
return false;
}
// ... magic byte check unchanged
}And update the call in ImportEpub::execute():
if (!$this->epubParser->isValidEpub($filePath, $uploadedFile['name'] ?? '')) {