ÿØÿà JFIF ÿá Exif MM * ÿÛ C
Server IP : 199.250.214.225 / Your IP : 3.144.25.14 Web Server : Apache System : Linux vps64074.inmotionhosting.com 3.10.0-1160.105.1.vz7.214.3 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : nicngo5 ( 1001) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /home/nicngo5/funds.upgrade.nicn.gov.ng/funds-upgraded/vendor/maatwebsite-old-2.1/excel/src/Maatwebsite/Excel/Classes/ |
Upload File : |
<?php namespace Maatwebsite\Excel\Classes; use PHPExcel_IOFactory; use Illuminate\Filesystem\Filesystem; use Maatwebsite\Excel\Exceptions\LaravelExcelException; class FormatIdentifier { /** * Available formats * * @var array * @access protected */ protected $formats = [ 'Excel2007', 'Excel5', 'Excel2003XML', 'OOCalc', 'SYLK', 'Gnumeric', 'CSV', 'HTML', 'PDF' ]; /** * Construct new format identifier * @param Filesystem $filesystem */ public function __construct(Filesystem $filesystem) { $this->filesystem = $filesystem; } /** * Get the file format by file * @param $file * @throws LaravelExcelException * @return string $format */ public function getFormatByFile($file) { // get the file extension $ext = $this->getExtension($file); // get the file format $format = $this->getFormatByExtension($ext); // Check if the file can be read if ($this->canRead($format, $file)) return $format; // Do a last try to init the file with all available readers return $this->lastResort($file, $format, $ext); } /** * Identify file format * @param $ext * @return string $format */ public function getFormatByExtension($ext) { switch ($ext) { /* |-------------------------------------------------------------------------- | Excel 2007 |-------------------------------------------------------------------------- */ case 'xlsx': case 'xlsm': case 'xltx': case 'xltm': return 'Excel2007'; break; /* |-------------------------------------------------------------------------- | Excel5 |-------------------------------------------------------------------------- */ case 'xls': case 'xlt': return 'Excel5'; break; /* |-------------------------------------------------------------------------- | OOCalc |-------------------------------------------------------------------------- */ case 'ods': case 'ots': return 'OOCalc'; break; /* |-------------------------------------------------------------------------- | SYLK |-------------------------------------------------------------------------- */ case 'slk': return 'SYLK'; break; /* |-------------------------------------------------------------------------- | Excel2003XML |-------------------------------------------------------------------------- */ case 'xml': return 'Excel2003XML'; break; /* |-------------------------------------------------------------------------- | Gnumeric |-------------------------------------------------------------------------- */ case 'gnumeric': return 'Gnumeric'; break; /* |-------------------------------------------------------------------------- | HTML |-------------------------------------------------------------------------- */ case 'htm': case 'html': return 'HTML'; break; /* |-------------------------------------------------------------------------- | CSV |-------------------------------------------------------------------------- */ case 'csv': case 'txt': return 'CSV'; break; /* |-------------------------------------------------------------------------- | PDF |-------------------------------------------------------------------------- */ case 'pdf': return 'PDF'; break; } } /** * Get the content type by file format * @param string $format * @return string $contentType */ public function getContentTypeByFormat($format) { switch ($format) { /* |-------------------------------------------------------------------------- | Excel 2007 |-------------------------------------------------------------------------- */ case 'Excel2007': return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8'; break; /* |-------------------------------------------------------------------------- | Excel5 |-------------------------------------------------------------------------- */ case 'Excel5': return 'application/vnd.ms-excel; charset=UTF-8'; break; /* |-------------------------------------------------------------------------- | HTML |-------------------------------------------------------------------------- */ case 'HTML': return 'HTML'; break; /* |-------------------------------------------------------------------------- | CSV |-------------------------------------------------------------------------- */ case 'CSV': return 'application/csv; charset=UTF-8'; break; /* |-------------------------------------------------------------------------- | PDF |-------------------------------------------------------------------------- */ case 'PDF': return'application/pdf; charset=UTF-8'; break; } } /** * Try every reader we have * @param $file * @param bool $wrongFormat * @param string $ext * @throws LaravelExcelException * @return string $format */ protected function lastResort($file, $wrongFormat = false, $ext = 'xls') { // Loop through all available formats foreach ($this->formats as $format) { // Check if the file could be read if ($wrongFormat != $format && $this->canRead($format, $file)) return $format; } // Give up searching and throw an exception throw new LaravelExcelException('[ERROR] Reader could not identify file format for file [' . $file . '] with extension [' . $ext . ']'); } /** * Check if we can read the file * @param $format * @param $file * @return boolean */ protected function canRead($format, $file) { if ($format) { $reader = $this->initReader($format); return $reader && $reader->canRead($file); } return false; } /** * Init the reader based on the format * @param string $format * @return \PHPExcel_Reader_IReader */ protected function initReader($format) { return PHPExcel_IOFactory::createReader($format); } /** * Get the file extension * @param string $file * @return string */ protected function getExtension($file) { return strtolower($this->filesystem->extension($file)); } }