How to check if an xls file is an editable file or not using phpexcel?

I have this bootstrap source file:

enter image description here

This input file only accepts the xls file, when I send the xls file, first I need to check php if the file is read or not, and return a specific number, because I only need to accept editable files.

An example of what I need:

I send the xls file, in php I check if the file is editable, if it is an editable file, go to the next step, and if it is not an editable file, return 3.

This is the only file to read:

enter image description here

I work with phpexcel, and when I send only the read file, I have the following error:

enter image description here

This is my code in php:

<?php require "dao/daoExcel.php"; require "vendor/autoload.php"; class ControllerExcel { private $aDatosExcel; public function setDataExcel($dataexcel) { $estado = true; if($this->moverArchivo($dataexcel)==false){ $estado = false; } if($estado == true && $this->validaHeaders($dataexcel)==false){ $estado = false; return 2; } if($estado == true){ return $this->setInsertExcel($dataexcel); } } public function moverArchivo($dataexcel) { $fileName = $_FILES["archivo"]["name"]; $fileTmpLoc = $_FILES["archivo"]["tmp_name"]; $aHeader = new DaoExcel(); $excelUrl = $aHeader->getHeaderExel($dataexcel); $pathAndName = $excelUrl[17]['par_valor'].$fileName; $moveResult = move_uploaded_file($fileTmpLoc, $pathAndName); if ($moveResult == true) { return true; }else{ return false; } } public function validaHeaders($dataexcel){ $inputFileType = 'Excel5'; $aHeader = new DaoExcel(); $excelHead = $aHeader->getHeaderExel($dataexcel); $inputFileName = $excelHead[17]['par_valor'].$_FILES["archivo"]["name"]; $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($inputFileName); $h1 = $objPHPExcel->getActiveSheet()->getCell('A1')->getValue(); $h2 = $objPHPExcel->getActiveSheet()->getCell('B1')->getValue(); $h3 = $objPHPExcel->getActiveSheet()->getCell('C1')->getValue(); $h4 = $objPHPExcel->getActiveSheet()->getCell('D1')->getValue(); $h5 = $objPHPExcel->getActiveSheet()->getCell('E1')->getValue(); $header = $h1."###".$h2."###".$h3."###".$h4."###".$h5; if($excelHead[16]['par_valor'] == $header){ return true; }else{ return false; } } public function setInsertExcel($dataexcel){ $inputFileType = 'Excel5'; $aHeader = new DaoExcel(); $excelHead = $aHeader->getHeaderExel($dataexcel); $inputFileName = $excelHead[17]['par_valor'].$_FILES["archivo"]["name"]; $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($inputFileName); $contRows = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow(); for($i=2;$i<=$contRows;$i++){ $h1 = $objPHPExcel->getActiveSheet()->getCell('A'.$i)->getValue(); $h2 = $objPHPExcel->getActiveSheet()->getCell('B'.$i)->getValue(); $h3 = $objPHPExcel->getActiveSheet()->getCell('C'.$i)->getValue(); $h4 = $objPHPExcel->getActiveSheet()->getCell('D'.$i)->getValue(); $h5 = $objPHPExcel->getActiveSheet()->getCell('E'.$i)->getValue(); $aDatos['ac_no']=$h1; $aDatos['custom_no']=$h2; $aDatos['nombre']=$h3; $aDatos['marc']=$h4; $aDatos['estado']=$h5; $aDatos['fecha_registro']=$this->setFecha(); $aDatos['rco_oculto']=0; $this->aDatosExcel[]=$aDatos; } return $aHeader->insertDatosExcel($this->aDatosExcel); } private function setFecha(){ date_default_timezone_set("America/Santiago"); $now = time(); putenv("TZ=America/Santiago"); $fecha=date("Ymd H:i:s",$now); $date=date("Y/m/d H:i:s", strtotime($fecha)); return $date; } } ?> 

So, I see that by default phpexcel only accepts editable files, but how can I check myself if the xls file is only readable or not with phpexcel and returns a message?

Sorry, my English.

+5
source share
1 answer
 echo $objPHPExcel->getSecurity()->isSecurityEnabled() ? 'some security is enabled' : 'no security is enabled'; 

a source

0
source

Source: https://habr.com/ru/post/1236361/


All Articles