original_string: public function zip()
      {
  
          if (empty($this->filepath)) {
              throw(new \Exception("Must set \sb\Email\Attachment::file_path before zipping attachment"));
          }
  
          if (empty($this->name)) {
              $this->name = basename($this->filepath);
          }
  
          $zip = new \ZipArchive();
          $zipfile_path = \ROOT . "/private/cache/compression/" . md5(microtime(true)) . '_' . $this->name . ".zip";
          $zip_dir = dirname($zipfile_path);
          if (!is_dir($zip_dir) && !@mkdir($zip_dir, 0755, true)) {
              throw(new \Exception("Cannot create /private/cache/compression directory\n"));
          }
  
          if ($zip->open($zipfile_path, \ZIPARCHIVE::CREATE) !== true) {
              throw(new \Exception("Cannot open <$zipfile_path>\n"));
          }
  
          $zip->addFromString($this->name, \file_get_contents($this->filepath));
  
          $zip->close();
  
          $this->name .= '.zip';
  
          //this is the content, in this case I am ready the blob data from a saved image file but you could easily replace this with blob data from a database.  The mime type will be added based on the extension using \sb\Files::extensionToMime.  For bizarre mime-types that are not in \sb\Files::extensionToMime you can override this by setting the mime-type manually $myAttachment->mime_type ='bizarre/weird';
          $this->contents = \file_get_contents($zipfile_path);
  
          //remove the tmp zip file
          \unlink($zipfile_path);
  
          //add mime type for zip files, \sb\Files should handle this after 1.41
          $this->mime_type = 'application/x-zip-compressed';
      }
code: public function zip()
      {
  
          if (empty($this->filepath)) {
              throw(new \Exception("Must set \sb\Email\Attachment::file_path before zipping attachment"));
          }
  
          if (empty($this->name)) {
              $this->name = basename($this->filepath);
          }
  
          $zip = new \ZipArchive();
          $zipfile_path = \ROOT . "/private/cache/compression/" . md5(microtime(true)) . '_' . $this->name . ".zip";
          $zip_dir = dirname($zipfile_path);
          if (!is_dir($zip_dir) && !@mkdir($zip_dir, 0755, true)) {
              throw(new \Exception("Cannot create /private/cache/compression directory\n"));
          }
  
          if ($zip->open($zipfile_path, \ZIPARCHIVE::CREATE) !== true) {
              throw(new \Exception("Cannot open <$zipfile_path>\n"));
          }
  
          $zip->addFromString($this->name, \file_get_contents($this->filepath));
  
          $zip->close();
  
          $this->name .= '.zip';
  
          //this is the content, in this case I am ready the blob data from a saved image file but you could easily replace this with blob data from a database.  The mime type will be added based on the extension using \sb\Files::extensionToMime.  For bizarre mime-types that are not in \sb\Files::extensionToMime you can override this by setting the mime-type manually $myAttachment->mime_type ='bizarre/weird';
          $this->contents = \file_get_contents($zipfile_path);
  
          //remove the tmp zip file
          \unlink($zipfile_path);
  
          //add mime type for zip files, \sb\Files should handle this after 1.41
          $this->mime_type = 'application/x-zip-compressed';
      }
code_tokens: public function zip ( ) { if ( empty ( $ this -> filepath ) ) { throw ( new \ Exception ( "Must set \sb\Email\Attachment::file_path before zipping attachment" ) ) ; } if ( empty ( $ this -> name ) ) { $ this -> name = basename ( $ this -> filepath ) ; } $ zip = new \ ZipArchive ( ) ; $ zipfile_path = \ ROOT . "/private/cache/compression/" . md5 ( microtime ( true ) ) . '_' . $ this -> name . ".zip" ; $ zip_dir = dirname ( $ zipfile_path ) ; if ( ! is_dir ( $ zip_dir ) && ! @ mkdir ( $ zip_dir , 0755 , true ) ) { throw ( new \ Exception ( "Cannot create /private/cache/compression directory\n" ) ) ; } if ( $ zip -> open ( $ zipfile_path , \ ZIPARCHIVE :: CREATE ) !== true ) { throw ( new \ Exception ( "Cannot open <$zipfile_path>\n" ) ) ; } $ zip -> addFromString ( $ this -> name , \ file_get_contents ( $ this -> filepath ) ) ; $ zip -> close ( ) ; $ this -> name .= '.zip' ; //this is the content, in this case I am ready the blob data from a saved image file but you could easily replace this with blob data from a database.  The mime type will be added based on the extension using \sb\Files::extensionToMime.  For bizarre mime-types that are not in \sb\Files::extensionToMime you can override this by setting the mime-type manually $myAttachment->mime_type ='bizarre/weird'; $ this -> contents = \ file_get_contents ( $ zipfile_path ) ; //remove the tmp zip file \ unlink ( $ zipfile_path ) ; //add mime type for zip files, \sb\Files should handle this after 1.41 $ this -> mime_type = 'application/x-zip-compressed' ; }
docstring: Zips the attachment before sending and sets the proper mime type
docstring_tokens: Zips the attachment before sending and sets the proper mime type