/** */ public function testRealPath() { $pathFiles = PHPOFFICE_COMMON_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')); }
/** * 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"); }
/** * @return string */ public function getMimeType() { if (!CommonFile::fileExists($this->getZipFileOut())) { throw new \Exception('File ' . $this->getZipFileOut() . ' does not exist'); } $oArchive = new \ZipArchive(); $oArchive->open($this->getZipFileOut()); if (!function_exists('getimagesizefromstring')) { $uri = 'data://application/octet-stream;base64,' . base64_encode($oArchive->getFromName($this->getZipFileIn())); $image = getimagesize($uri); } else { $image = getimagesizefromstring($oArchive->getFromName($this->getZipFileIn())); } return image_type_to_mime_type($image[2]); }
/** * 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); if (!function_exists('getimagesizefromstring')) { $uri = 'data://application/octet-stream;base64,' . base64_encode($oArchive->getFromName($pImgFile)); $image = getimagesize($uri); } else { $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"); } }
/** * 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"); } }