Example #1
0
 /**
  */
 public function testRealPath()
 {
     $pathFiles = PHPPOWERPOINT_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
     $this->assertEquals($pathFiles . 'Sample_01_Simple.pptx', File::realpath($pathFiles . 'Sample_01_Simple.pptx'));
     $this->assertEquals('zip://' . $pathFiles . 'Sample_01_Simple.pptx#[Content_Types].xml', File::realpath('zip://' . $pathFiles . 'Sample_01_Simple.pptx#[Content_Types].xml'));
     $this->assertEquals('zip://' . $pathFiles . 'Sample_01_Simple.pptx#/[Content_Types].xml', File::realpath('zip://' . $pathFiles . 'Sample_01_Simple.pptx#/rels/../[Content_Types].xml'));
 }
Example #2
0
 /**
  * Does a file support UnserializePHPPowerPoint ?
  *
  * @param  string    $pFilename
  * @throws \Exception
  * @return boolean
  */
 public function fileSupportsUnserializePHPPowerPoint($pFilename = '')
 {
     // Check if file exists
     if (!file_exists($pFilename)) {
         throw new \Exception("Could not open " . $pFilename . " for reading! File does not exist.");
     }
     // File exists, does it contain PHPPowerPoint.xml?
     return File::fileExists("zip://{$pFilename}#PHPPowerPoint.xml");
 }
Example #3
0
 /**
  * Get image mime type
  *
  * @param  string    $pFile Filename
  * @return string    Mime Type
  * @throws \Exception
  */
 private function getImageMimeType($pFile = '')
 {
     if (File::fileExists($pFile)) {
         if (strpos($pFile, 'zip://') === 0) {
             $pZIPFile = str_replace('zip://', '', $pFile);
             $pZIPFile = substr($pZIPFile, 0, strpos($pZIPFile, '#'));
             $pImgFile = substr($pFile, strpos($pFile, '#') + 1);
             $oArchive = new \ZipArchive();
             $oArchive->open($pZIPFile);
             $image = getimagesizefromstring($oArchive->getFromName($pImgFile));
         } else {
             $image = getimagesize($pFile);
         }
         return image_type_to_mime_type($image[2]);
     } else {
         throw new \Exception("File {$pFile} does not exist");
     }
 }