将mysql搜索结果url变量传递到第二个php处理器,以下载zip文件中的首选文件 SITREP
在Ubuntu 15.04上用PHP5.6.11和MySQLI5.6.30构建一个类似购物车的文档生成器/下载器的过程中。许多零件单独工作,但不能一起工作 数据库表包含产品的特定名称以及相应的文档URL(服务器上存储PDF的位置) 以下是由最终用户的工作流程决定的事件顺序:将mysql搜索结果url变量传递到第二个php处理器,以下载zip文件中的首选文件 SITREP,php,mysql,dynamic-arrays,Php,Mysql,Dynamic Arrays,在Ubuntu 15.04上用PHP5.6.11和MySQLI5.6.30构建一个类似购物车的文档生成器/下载器的过程中。许多零件单独工作,但不能一起工作 数据库表包含产品的特定名称以及相应的文档URL(服务器上存储PDF的位置) 以下是由最终用户的工作流程决定的事件顺序: 设置会话cookie。(待定,可能隐藏iframe)。PHP第1页 用户通过表单搜索、提交、回显数十个结果,并使用复选框匹配数据库中的url。PHP第1页 用户在几个框中选择要下载的项目。PHP第1页 用户搜索更多,请检查更
$results['url']
变量,创建zip,添加已检查的文件并提示下载$results['url']
从PHP#1上的数据库搜索结果传递到PHP#2下载处理器数组中。
PHP第1页,查询为:
$raw_results = mysql_query("SELECT * FROM mobilesearchspec
WHERE (`url` LIKE '%".$query."%') OR (`product` LIKE '%".$query."%') ORDER BY product ") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
echo "<p><input type=checkbox name=item[] value=$results[url]>" ; echo "".$results['product']."<br>";
echo "<a href='" .$results['url'] . "'>". $results['url'] . "</a>";
我对任何建议都持开放态度,并非常感谢按以下方式更改您的
foreach
循环
foreach ($files as $file){
$downloaded_file = file_get_contents($file);
$zip->addFromString(basename($file),$downloaded_file);
}
因此,第2页上的代码应该如下所示:
$files = $_POST['item'];
$timestamp = date("M-d-Y_H:i:s"); //$timestamp takes the current time
$zipname = "zip_".$timestamp.".zip"; // add timestamp to the file name
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file){
$downloaded_file = file_get_contents($file);
$zip->addFromString(basename($file),$downloaded_file);
}
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile("$zipname");
按以下方式更改您的
foreach
循环
foreach ($files as $file){
$downloaded_file = file_get_contents($file);
$zip->addFromString(basename($file),$downloaded_file);
}
因此,第2页上的代码应该如下所示:
$files = $_POST['item'];
$timestamp = date("M-d-Y_H:i:s"); //$timestamp takes the current time
$zipname = "zip_".$timestamp.".zip"; // add timestamp to the file name
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file){
$downloaded_file = file_get_contents($file);
$zip->addFromString(basename($file),$downloaded_file);
}
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile("$zipname");
将
元素置于while循环之外,这样您就可以使用第2页的$\u POST['item']
数组访问所有选中的URL。此外,这个下载按钮在哪里?搜索输入字段、清除表单按钮、提交搜索都是PHP之外的html格式。下载按钮的具体形式如下:
..
此外,您是否在第2页尝试过此功能,$files=$\u POST['item'代码>,这将为您提供一个URL数组。另外,发布第1页完整但相关的代码。@RajdeepPaul adding$files=$\u post['item']
to Page#2会触发zip文件,但其大小仅为43字节且无法打开=其为空。假设复选框表单没有从第1页传递url,对吗?可能是这样。要调试该问题,请执行var_dump($\u POST['item'])第2页的code>并查看您得到了什么。将
元素置于while循环之外,这样您就可以使用第2页的$\u POST['item']
数组访问所有选中的URL。此外,这个下载按钮在哪里?搜索输入字段、清除表单按钮、提交搜索都是PHP之外的html格式。下载按钮的具体形式如下:
..
此外,您是否在第2页尝试过此功能,$files=$\u POST['item'代码>,这将为您提供一个URL数组。另外,发布第1页完整但相关的代码。@RajdeepPaul adding$files=$\u post['item']
to Page#2会触发zip文件,但其大小仅为43字节且无法打开=其为空。假设复选框表单没有从第1页传递url,对吗?可能是这样。要调试该问题,请执行var_dump($\u POST['item'])代码>第2页,看看你得到了什么。