Сохраните защищенные данные Excel в PHPMyAdmin с помощью кода PHP и HTML - PullRequest
0 голосов
/ 17 октября 2019

Я все,

Я создаю базу данных для архивирования некоторых файлов Excel с PHPExcel и PHP моим администратором, но книгу Excel нужно защитить, как я могу открыть всю книгу с паролем в коде PHP? Возможно ли это?

Когда файл Excel без пароля, код работает отлично и все данные из книги Excel отправляются в базу данных.

Заранее спасибо!

Вот это код:

<?php
error_reporting(0); // ocult errors

mysqli_query($mysqli,"SET NAMES 'utf8'");
                        mysqli_query($mysqli,"SET character_set_connection=utf8");
                        mysqli_query($mysqli,"SET character_set_client=utf8");
                        mysqli_query($mysqli,"SET character_set_results=utf8");


$connect = mysqli_connect("localhost", "root", "", "2019"); //change the year on "2019"
mysqli_set_charset($connect,'utf8'); //put accentuation of words 
$output = '';

if(isset($_POST["import"]))
{
 $extension = end(explode(".", $_FILES["excel"]["name"])); // For getting Extension of selected file
 $allowed_extension = array("xls", "xlsx", "csv"); //allowed extension
 if(in_array($extension, $allowed_extension)) //check selected file extension is present in allowed extension array
 {
  $file = $_FILES["excel"]["tmp_name"]; // getting temporary source of excel file
  include("Classes/PHPExcel/IOFactory.php"); // Add PHPExcel Library in this code
  $objPHPExcel = PHPExcel_IOFactory::load($file); // create object of PHPExcel library by using load() method and in load method define path of selected file

  $output .= "<label class='text-success'>Data Inserted</label><br /><table class='table table-bordered'>"; //table in html page
  foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
  {

   /* echo 'Worksheet number - ', $objPHPExcel->getIndex($worksheet), PHP_EOL; */ //see the number of every sheet from excel

   $highestRow = $worksheet->getHighestRow();
   for($row=5; $row<=$highestRow; $row++)
   {
    $output .= "<tr>";

    $point = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(0, $row)->getCalculatedValue());
    $description = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(1, $row)->getCalculatedValue());
    $c = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(2, $row)->getCalculatedValue());
    $d = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(3, $row)->getCalculatedValue());
    $e = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(4, $row)->getCalculatedValue());
    $f = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(5, $row)->getCalculatedValue());
    $g = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(6, $row)->getCalculatedValue());
    $h = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(7, $row)->getCalculatedValue());
    $i = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(8, $row)->getCalculatedValue());
    $j = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(9, $row)->getCalculatedValue());
    $k = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(10, $row)->getCalculatedValue());

    $query = "INSERT INTO tbl_excel(point, description, c, d, e, f, g,h,i,j,k) VALUES ('".$point."','".$description."', '".$c."', '".$d."', '".$e."', '".$f."', '".$g."', '".$h."', '".$i."', '".$j."', '".$k."')";
    mysqli_query($connect, $query);
    $output .= '<td>'.$point.'</td>';
    $output .= '<td>'.$description.'</td>';
    $output .= '<td>'.$c.'</td>';
    $output .= '<td>'.$d.'</td>';
    $output .= '<td>'.$e.'</td>';
    $output .= '<td>'.$f.'</td>';
    $output .= '<td>'.$g.'</td>';
    $output .= '<td>'.$h.'</td>';
    $output .= '<td>'.$i.'</td>';
    $output .= '<td>'.$j.'</td>';
    $output .= '<td>'.$k.'</td>';
    $output .= '</tr>';
   }
  } 
  $output .= '</table>';

 }
 else
 {
  $output = '<label class="text-danger">Invalid File</label>'; //if non excel file then
 }
}
?>

<html>
 <head>
  <title>Import Excel to Mysql using PHPExcel in PHP</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> 
  <style>
  body
  {
   margin:0;
   padding:0;
   background-color:#f1f1f1;
  }
  .box
  {
   width:700px;
   border:1px solid #ccc;
   background-color:#fff;
   border-radius:5px;
   margin-top:100px;
  }

  </style>
 </head>
 <body>
  <div class="container box">
   <h3 align="center">Import Excel to Mysql using PHPExcel in PHP</h3><br />
   <form method="post" enctype="multipart/form-data">
    <label>Select Excel File</label>
    <input type="file" name="excel" />
    <br />
    <input type="submit" name="import" class="btn btn-info" value="Import" />
   </form>
   <br />
   <br />
   <?php
   echo $output;
      ?>
  </div>
 </body>
</html>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...