Pregunta

I am working on a PHP application which downloads an ePub file. As part of the code I am adding a unique identifier which can be used to trace the original download information in a database to combat piracy.

I am using PHP ZipArchive functions to add an archive comment to the file but it seems that Adobe Digital editions is unable to open the ePub file if there is a comment present. When the comment is removed it opens fine so I just want to see if anyone else has had this problem before and if there is a way to add a comment to the ePub file which will allow Adobe Digital Editions to open it. Below is the code I'm using:

public function secureEpub($file, $download_id, $filepath){

    //GENERATE RANDOM FILE NAME
    $newFile = uniqid().".epub";
    //COPY EPUB AND WORK FROM THAT VERSION
    copy($file, $filepath.$newFile);

    //TREAT EPUB FILE AS ORDINARY ZIP ARCHIVE
    //OPEN AND EXTRACT EPUB
    $zip = new ZipArchive;
    $res = $zip->open($filepath.$newFile);
    if($res === TRUE){
        //ZIP ARCHIVE HAS OPENED SUCCESSFULLY - SET ARCHIVE COMMENT TO DOWNLOAD ID
        $zip->setArchiveComment($download_id);
        $zip->close();
    } else {
        error_log('Unable to open ePub (' . $filepath.$newFile . ') as Directory');
        return false;   
        exit;
    }
    //ONCE CHANGE HAS BEEN MADE CLOSE THE ARCHIVE AND RETURN TEMP FILE
    return $filepath.$newFile;

}

As you can see it copies the original, creates an Archive comment then returns the file (which is later deleted). Is there a way of achieving this without corrupting the ePub (for ADE)?

Let me know if I've not made any sense :D

P.S: Just to clarify, the download works fine and the comment is applied correctly. It is just that ADE is unable to open it while other ePub readers manage fine. Am I going about it in the wrong way?

¿Fue útil?

Solución

OK, I couldn't find a way around this so I kind of came up with a solution. You can add a new file or directory inside the ZIP file which had the details included.

So, you can use something like:

$zip->addFromString('test.txt', $download_id);

or create a directory named after the download like:

$zip->addEmptyDir($download_id);

Would probably recommend being a bit more obscure with naming though if you get stuck like I did :)

Thanks

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top