PHP脚本可以在本地主机上正常下载,但在实时站点上输出文件
原谅我,我是PHP的处女,我正在为wordpress编写一个插件,允许某人向客户销售代码,插入该客户,然后访问该网站,将代码输入文本框并点击提交。php脚本然后检查mysql是否存在该代码,如果它存在,它将启动下载,因为它的销售下载(zip中的照片)它获取服务器上给定的文件名(没有扩展名),然后将其作为文件名输出,该文件名应放在“另存为”框中以供下载,就在我完成代码的功能时,我在第一次本地测试之后在一个实时站点上测试它。。。现在这是本地主机(xampp)上的问题,它启动下载并在实时站点上正常工作,它执行以下操作: 这是我的代码:PHP脚本可以在本地主机上正常下载,但在实时站点上输出文件,php,wordpress,file,download,output,Php,Wordpress,File,Download,Output,原谅我,我是PHP的处女,我正在为wordpress编写一个插件,允许某人向客户销售代码,插入该客户,然后访问该网站,将代码输入文本框并点击提交。php脚本然后检查mysql是否存在该代码,如果它存在,它将启动下载,因为它的销售下载(zip中的照片)它获取服务器上给定的文件名(没有扩展名),然后将其作为文件名输出,该文件名应放在“另存为”框中以供下载,就在我完成代码的功能时,我在第一次本地测试之后在一个实时站点上测试它。。。现在这是本地主机(xampp)上的问题,它启动下载并在实时站点上正常工作
$fileonS = $_SERVER['DOCUMENT_ROOT'] . "/wp-content/plugins/photo_dwn_man/downloads/" . $codeRResult;
//download file (NEEDS MORE LOOKING INTO THIS IS JUST THE BASICS)
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $codeOResult . '.zip');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($fileonS));
ob_clean();
flush();
readfile($fileonS);
exit;
希望你们能帮助我或者给我指出正确的方向,请解释一下,因为我在这里学习的是不要抄袭
问候,,
亚当这可能是由许多因素造成的。最常见的两个原因是:
请检查服务器的内部设置并查看是否启用了php。如果已启用,请尝试重新配置服务器&php。如果问题仍然存在,您应该在某个朋友的服务器上进行检查,看看问题是否出在您的服务器上。对,我就是这样解决的。。。我不得不将标题部分添加到一个单独的PHP文件中,当输入并提交正确的代码时,我调用了一些JavaScript来加载PHP并传递一些GET变量
我的单独文件包含:
<?php
$getcodeOResult = $_GET['gcor'];
$getcodeRResult = $_GET['gcsr'];
$fileonS = $_SERVER['DOCUMENT_ROOT'] . "/wp-content/plugins/photo_dwn_man/downloads/" . $getcodeRResult;
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $getcodeOResult . '.zip');
header('Content-Transfer-Encoding: binary');
header('Pragma: public');
header('Content-Length: ' . filesize($fileonS));
ob_clean();
flush();
readfile($fileonS);
?>
function startDownload() {
// This function handles the download start
// Get filename you want user to download by getting the contents of dB row that matches the user input
$theCodeOfile = $GLOBALS['wpdb']->get_col( "SELECT dwn_file FROM wp_photodwnman WHERE dwn_code='" . $GLOBALS['userCode'] . "'");
// Get the actual servers filename by getting the contents of dB row that matches the user input
$theCodeRfile = $GLOBALS['wpdb']->get_col( "SELECT dwn_pseu FROM wp_photodwnman WHERE dwn_code='" . $GLOBALS['userCode'] . "'");
// join both results into a string and not an array
$codeOResult = join("", $theCodeOfile);
$codeRResult = join("", $theCodeRfile);
$GLOBALS['wpdb']->query( "UPDATE wp_photodwnman SET dwn_count=dwn_count+1 WHERE dwn_code='" . $GLOBALS['userCode'] . "'");
// adds to variable the location and filename
echo "<script>window.onload = function(){window.location.href='http://ctwo12photography.co.uk/wp-content/plugins/photo_dwn_man/dwnload.php?gcor=" . $codeOResult . "&gcsr=" . $codeRResult . "'}; </script>";
}
然后,启动下载的功能如下所示:
<?php
$getcodeOResult = $_GET['gcor'];
$getcodeRResult = $_GET['gcsr'];
$fileonS = $_SERVER['DOCUMENT_ROOT'] . "/wp-content/plugins/photo_dwn_man/downloads/" . $getcodeRResult;
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $getcodeOResult . '.zip');
header('Content-Transfer-Encoding: binary');
header('Pragma: public');
header('Content-Length: ' . filesize($fileonS));
ob_clean();
flush();
readfile($fileonS);
?>
function startDownload() {
// This function handles the download start
// Get filename you want user to download by getting the contents of dB row that matches the user input
$theCodeOfile = $GLOBALS['wpdb']->get_col( "SELECT dwn_file FROM wp_photodwnman WHERE dwn_code='" . $GLOBALS['userCode'] . "'");
// Get the actual servers filename by getting the contents of dB row that matches the user input
$theCodeRfile = $GLOBALS['wpdb']->get_col( "SELECT dwn_pseu FROM wp_photodwnman WHERE dwn_code='" . $GLOBALS['userCode'] . "'");
// join both results into a string and not an array
$codeOResult = join("", $theCodeOfile);
$codeRResult = join("", $theCodeRfile);
$GLOBALS['wpdb']->query( "UPDATE wp_photodwnman SET dwn_count=dwn_count+1 WHERE dwn_code='" . $GLOBALS['userCode'] . "'");
// adds to variable the location and filename
echo "<script>window.onload = function(){window.location.href='http://ctwo12photography.co.uk/wp-content/plugins/photo_dwn_man/dwnload.php?gcor=" . $codeOResult . "&gcsr=" . $codeRResult . "'}; </script>";
}
函数startDownload(){
//此函数用于处理下载启动
//通过获取与用户输入匹配的dB行内容,获取您希望用户下载的文件名
$theCodeOfile=$GLOBALS['wpdb']->get_col(“从wp_photownman中选择dwn_文件,其中dwn_代码=””。$GLOBALS['userCode']。“”);
//通过获取与用户输入匹配的dB行的内容来获取实际的服务器文件名
$theCodeRfile=$GLOBALS['wpdb']->get_col(“从wp_photownman中选择dwn_pseu,其中dwn_code='””。$GLOBALS['userCode']。“”);
//将两个结果合并为字符串而不是数组
$codeOResult=join(“,$theCodeOfile”);
$codeRResult=join(“,$theCodeRfile”);
$GLOBALS['wpdb']->query(“更新wp\u photodwnman SET dwn\u count=dwn\u count+1,其中dwn\u code=””。“$GLOBALS['userCode'.””);
//向变量添加位置和文件名
echo“window.onload=function(){window.location.href=”http://ctwo12photography.co.uk/wp-content/plugins/photo_dwn_man/dwnload.php?gcor=“$codeRResult.”&gcsr=“.$codeRResult.”};”;
}
所以我从来没有弄清楚它为什么会这样,但这提供了一个解决方案 这是wordpress中的一个插件,wordpress是用php编写的,因此我无法想象这就是为什么,脚本本身工作正常,功能正常,但当它在本地服务器上下载时,在live服务器上就可以了,它在屏幕上以文本形式输出文件,但所有wordpress模板都完好无损。p.s。我使用的是完整的php标签。我开始认为它可能与live server上的内部服务器设置有关,如果我不知道它可能是什么……正如其他答案中提到的,WORDPRESS是用php构建的,如果没有启用php,WORDPRESS甚至无法工作!我的插件脚本的所有其他部分也不会,问题只在于下载!