1

I've created a content type that upload files .epub on database. Now for some reason (to use epub on a mobile app) I need to get the file .epub uncompressed.

It's like in my content type I upload a .zip file but when drupal store it it's stored unzipped.

Did someone knows a Drupal API function or a method that uncompress or unzip a .epub files?

Note that when I upload an .epub file or .jpg image or any other type of extensions, in the table file_managed I always get filemime : "application/octet-stream"? is it normal ?

  • Is this functionality to be exposed exposed to a moderated and manged group of users, or to anonymous users as well? – Screenack Aug 23 '15 at 17:29
  • Hi, the upload of an .epub is done by the admin – Mitch Aug 23 '15 at 17:45
1

PHP already has a built in class to process zip files. You can combine that with a hook_node_presave invocation in a custom module to process the field containing your ePub file and extract it to a directory in your file system.

/**
 * Implements hook_node_presave().
 */
function MYMODULE_node_presave($node) {
  if(isset($node->field_MYFIELD[LANGUAGE_NONE][0]['fid'])) {
    $file = file_load($node->field_sss[LANGUAGE_NONE][0]['fid']);
    $file_path = drupal_realpath($file->uri);
    $file_name = pathinfo($file_path, PATHINFO_FILENAME);
    $zip = new ZipArchive;
    if ($zip->open($file_path)) {
      $zip->extractTo(drupal_realpath("public://MYMODULE_customdir/$file_name"));
      $zip->close();
    }
  }
}
  • Just tested it, it's all that that i wanted Shawn, thank you again ! – Mitch Aug 24 '15 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.