- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是一名新开发人员,最近为我的公司完成了一个简单的 PHP mySQL DBMS 的编码。现在我已经完成了它的工作,我想确保它的安全,实现我可以在网络上找到的所有安全最佳实践(例如:正则表达式,在网络目录之外包含 mysqli_connect.php与脚本内的连接字符串等)在我将其上线之前。我在这段代码之外编辑了一些个人信息,并将其替换为它的工作内容,但放在括号内。如果可能的话,我不想将其发布在网上。
通常,我只需引用 mysqli_connect.php 就可以使用我的数据库,如下所示:
require_once('..\mysqli_connect.php');
我的 DBMS 上的功能之一是“下载到 Excel”按钮。它工作完美,但只有当我直接在文件内部建立连接时。如果我尝试像上面的示例中那样编写连接,Excel 文件会显示以下错误消息:
Excel 无法打开文件“xyz.xlsx”,因为文件格式或扩展名无效。验证文件未损坏并且文件扩展名与文件格式匹配。
当我直接在 ExcelDownload.php 中写入连接时,Excel 文件可以正确下载。连接字符串如下所示:
$dbc = @mysqli_connect('[myhost]', '[myusername]', '[mypassword]', '[mydatabase]')
所以,基本上,间接引用连接会导致我的 Excel 下载出现错误,但我不知道为什么。如果我直接调用连接,效果很好。任何帮助将不胜感激。
再次感谢吉布里尔
顺便说一句,这是 ExcelDownload.php:
<?php
session_start();
//VERIFY LOGGED IN: Redirects user back to home page if they are not logged in or if they don't have the right privileges. Should be atop every page.
if(!isset($_SESSION['id']))
{header("Location: login.php");}
//CALLS PHPEXCEL: Creates connection to PHPExcel class library, and creates new instance of PHPExcel.
// From there it sets the attributes for some of PHPExcel's methods, to explain how we want the spreadsheet to be designed.
require_once 'Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->setTitle('OpenOrders');
$objPHPExcel->getActiveSheet()->setCellValue('A1', '[my company]');
//CONFIRMATION: If Export to Excel button is pushed, then do this
if(isset($_POST["export_Excel"]))
{
//DANGER!! UNSECURED DATABASE CONNECTION. BAD PRACTICE. CHANGE IN NEXT VERSION!
//GENERATE QUERY: Connects to database -- Once connected, runs select * query and saves the outcome in $result
$dbc = @mysqli_connect( '[myhost]', '[myusername]', '[mypassword]', '[mydb]')
OR die ('Could not connect to MySQL ' . mysqli_connect_error());
$sql = "[myquery]";
$result = mysqli_query($dbc, $sql);
//SET HEADING VALUE: Sets the values for the top row of the spreadsheet, which will be the headings.
$objPHPExcel->getActiveSheet()->setCellValue('C3', 'OOPONO');
$objPHPExcel->getActiveSheet()->setCellValue('D3', 'Order Status');
$objPHPExcel->getActiveSheet()->setCellValue('E3', 'Order Comments');
//ITERATOR: If there are values inside of $result, starting at row 4, insert values for OOPONO, order status, and comments until $results is totally intereated.
if(mysqli_num_rows($result) > 0)
{
$rownumber = 4;
while ($row = mysqli_fetch_array($result))
{
$row1 = 'C'.$rownumber;
$objPHPExcel->getActiveSheet()->setCellValue($row1, $row["OOPONO"]);
$row1 = 'D'.$rownumber;
$objPHPExcel->getActiveSheet()->setCellValue($row1, $row["Order_Status"]);
$row1 = 'E'.$rownumber;
$objPHPExcel->getActiveSheet()->setCellValue($row1, $row["Comments"]);
$rownumber = $rownumber + 1;
}
}
}
//DOWNLOAD SETUP: Defines the different attributes of the Excel doc ranging from filename to extension. It also does the finishing touches of setting up the download.
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="OpenOrders.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
?>
最佳答案
So again, basically, referencing the connection indirectly causes my Excel download to bug out and I don't know why. It works fine if I directly summon the connection.
不! 间接引用连接会导致
错误,从而导致错误消息发送到您的显示器;然后 Excel 输出也会发送到您的显示器,从而使错误消息成为 Excel 数据流内容的一部分,从而将错误消息注入(inject)到文件中,从而导致文件损坏。
在文本编辑器中打开文件,您应该能够看到收到的实际错误消息
关于php - 引用 mysqli_connect.php 破坏 PHPExcel 下载程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38755123/
我正在尝试完成撤消/重做。我正在使用loadFromJSON(...)从我存储在数组中的 Canvas 状态重新构建 Canvas 。基本上,我的想法是破坏现有的 Canvas 并重新构建 Canva
在某些情况下,我有一个在 iframe 中打开的网页。当它被加载到那个 iframe 中时,我需要它将窗口位置设置为资源以下载文件(所有这些都是为了更新 GreaseMonkey 脚本......所有
当我创建 Intent 时: Intent in = new Intent(this, myclass.class); this.startActivity(in); 我创建了一个新的 Intent
我正在我本地版本的 Wordpress 网站上为 Wordpress 创建新的短代码。 在 functions.php 中,我添加了例如: function shortTest() { re
我正在为机械网站制作 JavaScript 闪卡游戏。因为我想将方程写在卡片上,所以我需要使用 delta(Δ) 符号。 一张卡片可能有:一侧是“功率方程”,另一侧是“P=W/Δt”。如果卡片从第一面
我编写了以下代码: document.addEventListener("DOMContentLoaded", ()=>{ let menu = document.querySelector(
我的浏览器同步工作正常,但我仍然很难处理之前的 html 的缓存。即使选中了 Chrome 的“禁用缓存”,甚至在隐身模式下也是如此! 要加载页面更改,我总是必须“清除缓存并硬重新加载”。 我想知道,
我注意到每次打开和关闭(通过单击菜单项或单击菜单外的某个区域)时,上下文菜单 ( Ext.menu.Menu ) s 不会从 DOM 中删除,它们只是以某种方式变得不可见。 如何改变这个? 最佳答案
给定依赖记录类型: Record FinPath : Type := mkPath { fp_head : S i; fp_tail
在 Husdon/Jenkins 中,我可以在构建被破坏时设置通知,以向进行破坏构建的 checkin 的用户发送电子邮件。如何在 Teamcity 中执行此操作? 我知道个人用户可以通过 Teamc
我注意到每次打开和关闭(通过单击菜单项或单击菜单外的某个区域)时,上下文菜单 ( Ext.menu.Menu ) s 不会从 DOM 中删除,它们只是以某种方式变得不可见。 如何改变这个? 最佳答案
使用 MIMEMultipart('alternative') 发送 html 和 pain-text 时 将 html 转换为文本时,html 的 anchor 换行 http://127.0.0.
每当我的应用程序最小化时,我都会启动一个服务,该服务向我的 HTTP 服务器发送拉取请求以检查通知,当应用程序恢复时,服务将被终止(以及计划的可运行项)。一切正常,直到我决定终止该应用程序(将其从正在
我意识到该框架处于 alpha 阶段,但正在实现 jQuery Mobile破坏了我的omniauth 身份验证。当我尝试登录时,一旦我尝试点击/auth/twitter Controller ,jQ
我对 Angular 比较陌生,经过几个小时的调试,我发现添加 jquery 时存在一些不兼容性。该指令在没有 jquery 的情况下工作正常,但在使用 jquery 时会中断:/ 这是一个 plnk
我发现,因为我正在处理的所有表单都有一个包含“name =“submit””属性的提交按钮,所以当我单击应该触发表单提交的链接时,触发器提交会中断. 有谁知道我该如何解决这个问题。 下面的 JQuer
我遇到了一个问题:/我得到了一个 CSS 东西,它使悬停时背景位置发生变化。但是当我在 javascript 中运行一个改变悬停的函数后,CSS 停止工作。 这是函数: function tree()
谁能给出一个完整的例子来说明 qooxdoo 1.6 中的 dispose 和 destruct 是如何工作的? ,我在 qooxdoo 演示或文档中找不到任何好的示例。 谢谢你的建议。 最佳答案 处
我对 JFormattedTextField 有疑问(我将它用作我们所有文本字段的基类)。 今天我尝试向该字段的文档添加一个文档过滤器,它工作得很好,但前提是它没有设置格式化程序工厂。 问题是,当设置
我有一个点击事件 $('#ship_Move').click(function (event) { event.stopPropagation();
我是一名优秀的程序员,十分优秀!