0

原谅我,我在 PHP 方面完全是处女,我正在为 wordpress 编写一个插件,允许某人向客户出售代码,然后该客户访问该站点并将该代码输入到文本框中并点击提交。然后 php 脚本检查 mysql 是否存在该代码,如果它存在,它将启动下载,因为它的销售下载(zip 中的照片)它会抓取服务器上给出的没有扩展名的文件名,然后将其输出为它应该在的文件名用于下载的另存为框,就像我完成代码的功能一样,我在第一次在本地测试后在实时站点上对其进行测试......现在这是本地主机(xampp)上的问题,它开始下载并且工作正常在现场它这样做:

http://www.ctwo12.com/output.png

这是我的代码:

$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;

希望你们能帮助或指出我正确的方向,也请解释一下,因为我是来学习而不是复制的!

问候,亚当

4

3 回答 3

0

这可能是由许多事情引起的。两个最常见的原因是:

  1. 您的服务器上未启用 PHP

  2. 您的代码正在使用 php 短标签,并且服务器已将它们关闭<?vs<?php

于 2013-05-25T07:25:30.143 回答
0

检查服务器的内部设置并查看是否启用了 PHP。如果已启用,请尝试重新配置您的服务器和 php.ini。如果问题仍然存在,你应该在朋友的服务器上检查一下,看看你的服务器是否有问题。

于 2013-05-26T13:56:29.100 回答
0

对,这就是我修复它的方式......我必须将标题部分添加到一个单独的 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>";
}

所以我从来没有深入了解它为什么会这样,但这提供了一个解决方案!

于 2013-05-29T09:58:54.373 回答