1 | <?php |
||
7 | class ZipFile extends AbstractDrawingAdapter |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $path; |
||
13 | |||
14 | /** |
||
15 | * Get Path |
||
16 | * |
||
17 | * @return string |
||
18 | */ |
||
19 | 2 | public function getPath() |
|
23 | |||
24 | /** |
||
25 | * Set Path |
||
26 | * |
||
27 | * @param string $pValue File path |
||
28 | * @return \PhpOffice\PhpPresentation\Shape\Drawing |
||
29 | */ |
||
30 | 2 | public function setPath($pValue = '') |
|
35 | |||
36 | /** |
||
37 | * @return string |
||
38 | */ |
||
39 | 1 | public function getContents() |
|
40 | { |
||
41 | 1 | if (!CommonFile::fileExists($this->getZipFileOut())) { |
|
42 | 1 | throw new \Exception('File '.$this->getZipFileOut().' does not exist'); |
|
43 | } |
||
44 | |||
45 | $imageZip = new \ZipArchive(); |
||
46 | $imageZip->open($this->getZipFileOut()); |
||
47 | $imageContents = $imageZip->getFromName($this->getZipFileIn()); |
||
48 | $imageZip->close(); |
||
49 | unset($imageZip); |
||
50 | return $imageContents; |
||
51 | } |
||
52 | |||
53 | |||
54 | /** |
||
55 | * @return string |
||
56 | */ |
||
57 | 1 | public function getExtension() |
|
61 | |||
62 | /** |
||
63 | * @return string |
||
64 | */ |
||
65 | public function getMimeType() |
||
66 | { |
||
67 | if (!CommonFile::fileExists($this->getZipFileOut())) { |
||
68 | throw new \Exception('File '.$this->getZipFileOut().' does not exist'); |
||
69 | } |
||
70 | $oArchive = new \ZipArchive(); |
||
71 | $oArchive->open($this->getZipFileOut()); |
||
72 | if (!function_exists('getimagesizefromstring')) { |
||
73 | $uri = 'data://application/octet-stream;base64,' . base64_encode($oArchive->getFromName($this->getZipFileIn())); |
||
74 | $image = getimagesize($uri); |
||
75 | } else { |
||
76 | $image = getimagesizefromstring($oArchive->getFromName($this->getZipFileIn())); |
||
77 | } |
||
78 | return image_type_to_mime_type($image[2]); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @return string |
||
83 | */ |
||
84 | public function getIndexedFilename() |
||
85 | { |
||
86 | $output = pathinfo($this->getZipFileIn(), PATHINFO_FILENAME); |
||
87 | $output = str_replace('.' . $this->getExtension(), '', $output); |
||
88 | $output .= $this->getImageIndex(); |
||
89 | $output .= '.'.$this->getExtension(); |
||
90 | $output = str_replace(' ', '_', $output); |
||
91 | return $output; |
||
92 | } |
||
93 | |||
94 | 1 | protected function getZipFileOut() |
|
100 | |||
101 | 1 | protected function getZipFileIn() |
|
107 | } |
||
108 |