Php 如何在网站上显示多个单独的PDF/Excel文档?
我有一个客户,需要在我为他设计的网站上显示100个价格表,每个用户一个。我知道如何使用PHP,但我还没有找到一种在网站上显示特定于每个用户的文档的好方法 我的第一个解决方案是构建一个函数,在数组中搜索特定的经销商id。该经销商id将链接到嵌入代码,然后通过PHP插入页面 上述方法的问题是,它不能处理超过3个条目。至少从我的经验来看 这是我的旧方法代码。据我所知,语法是正确的Php 如何在网站上显示多个单独的PDF/Excel文档?,php,html,pdf,iframe,web,Php,Html,Pdf,Iframe,Web,我有一个客户,需要在我为他设计的网站上显示100个价格表,每个用户一个。我知道如何使用PHP,但我还没有找到一种在网站上显示特定于每个用户的文档的好方法 我的第一个解决方案是构建一个函数,在数组中搜索特定的经销商id。该经销商id将链接到嵌入代码,然后通过PHP插入页面 上述方法的问题是,它不能处理超过3个条目。至少从我的经验来看 这是我的旧方法代码。据我所知,语法是正确的 ini_set('memory_limit', '1024M'); include_once("check_login_s
ini_set('memory_limit', '1024M');
include_once("check_login_status.php");
$log_dealer = $_SESSION['dealer'];
function assignPriceSheet($log_username) {
$array = array("<iframe src='pricesheets/Price Sheet.pdf' height='750' width='800'>" => '333333'
, "<iframe src='pricesheets/Price Sheet.pdf' height='750' width='800'>" => '115'
, "<iframe src='pricesheets/Price Sheet.pdf' height='750' width='800'>" => '122'
, "<iframe src='pricesheets/Price Sheet.pdf' height='750' width='800'>" => '136'
, "<iframe src='pricesheets/Price Sheet.pdf' height='750' width='800'>" => '137'
, "<iframe src='pricesheets/Price Sheet.pdf' height='750' width='800'>" => '167'
, "<iframe src='pricesheets/Price Sheet.pdf' height='750' width='800'>" => '169'
, "<iframe src='pricesheets/Price Sheet.pdf' height='750' width='800'>" => '172'
, "<iframe src='pricesheets/Price Sheet.pdf' height='750' width='800'>" => '173'
, "<iframe src='pricesheets/Price Sheet.pdf' height='750' width='800'>" => '199'
, "<iframe src='pricesheets/Price Sheet.pdf' height='750' width='800'>" => '208'
, "<iframe src='pricesheets/Price Sheet.pdf' height='750' width='800'>" => '217'
, "<iframe src='pricesheets/Price Sheet.pdf' height='750' width='800'>" => '596017');
//Returns the price sheet of the logged in user
return array_search($log_username, $array);
}
ini_集('memory_limit','1024M');
包括一次(“check_login_status.php”);
$log_dealer=$_会话['dealer'];
函数分配价格表($log\u用户名){
$array=array(“=>”333333“
, "" => '115'
, "" => '122'
, "" => '136'
, "" => '137'
, "" => '167'
, "" => '169'
, "" => '172'
, "" => '173'
, "" => '199'
, "" => '208'
, "" => '217'
, "" => '596017');
//返回登录用户的价格表
返回数组搜索($log\u username,$array);
}
通常,函数中会有大约400多个条目(我只是想缩短代码长度)
如有其他解决方案,将不胜感激 第一个解决方案(如上所述使用数组)
因为我不相信他想要一次全部四百个,我会根据需要使用Ajax逐个加载。不,他不想要一次全部四百个。每个价格表都分配给一个单独的用户。我希望用户能够登录并查看他们的价格表。我已经在网站中实现了ajax,但是您如何显示每个用户的价格表呢?好的,请继续关注,我将尝试解释我的方法;)你能把电子表格转换成HTML表格吗?在我看来,呈现数据的方式更为准确、快捷。@halfer-Yeah。。有几个应用程序。。但这是一个混乱的过程。尤其是有了更多的图形电子表格。伙计,我不在乎这是否有效。我将把你的回答作为我问题的答案。你这该死的石头!!实际上,我今天必须下班,但明天我将实施其中一个解决方案。非常感谢@nate_dawg它一定有用;)如果你需要进一步的帮助,就给我写张便条。
// PHP
// define somewhere this array
$price_list = array (
"username_1" => "/some-folder/price_list_1.php",
"username_2" => "/some-folder/price_list_2.php",
"username_3" => "/some-folder/price_list_3.php"
);
// your price_list.php file
// you may have all of this in one .php file as well
if(isset($_SESSION) && user_is_authorized()){ // check if the user is logged in
echo "<iframe src='" . $price_list[$_SESSION['username']] . "' height='750' width='800'>";
}
// you may name the price_list for each user according to their username and you'll have something like this
if(isset($_SESSION) && user_is_authorized()){ // check if the user is logged in
echo "<iframe src='/some-folder/" . $_SESSION['username'] . "_price_list.pdf' height='750' width='800'>";
}
// you may load the price_list on onload or an onclick event
// don't pass any id with URL due to security issues
window.onload = function(){
var button = document.geElementById('price_list');
button.onclick = function(){
var xhr = new XMLHttpRequest();
var url = "pricelist.php";
xhr.open("GET", url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
document.getElementById('price_list_container').innerHTML = xhr.responseText;
}
};
xhr.send();
};
};