I have this input file bootstrap:
This input file only accept xls file, when I send the xls file, first I need check in php if the file is only read or not and return a specific number, because I need accept only editable files.
Example what I need:
I send a xls file, in php I check if is a editable file , if is editable file , continue with the next step, and if is not a editable file, return 3.
This is a only read file:
I work with phpexcel and when I send a only read file , I have the next error:
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("Y-m-d H:i:s",$now);
$date=date("Y/m/d H:i:s", strtotime($fecha));
return $date;
}
}
?>
So I see that by default,phpexcel only accept editable files , but how can I check by my self if a xls file is only read or not with phpexcel , and return a message?
Sorry by my english.
echo $objPHPExcel->getSecurity()->isSecurityEnabled() ? 'some security is enabled' : 'no security is enabled';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.