Phpcms2007 SP6丢失下载地址参数Bug解决方法

在Phpcms2007 SP6下载频道中添加的下载地址如果形如:

引用内容 引用内容
电信下载|http://www.mzwu.com/interface/creategames.aspx?uid=11476&resid=160&fileid=1087

在点击下载的时候你会发现下载地址却成了:

引用内容 引用内容
http://www.mzwu.com/interface/creategames.aspx?uid=11476

可见,下载地址&之后的参数丢失了,下边我们来找找原因。

打开module/down/download.inc.php,找到"parse_str($auth);",在其后面增加代码:
echo $auth."<br/>";
echo $fileurl."<br/>";
exit();

浏览页面,输出内容如下:
引用内容 引用内容
downid=1&fileurl=http://www.mzwu.com/interface/creategames.aspx?uid=11476&resid=160&fileid=1087&starttime=1213948944&ip=127.0.0.1&mirror=
http://www.mzwu.com/interface/creategames.aspx?uid=11476

可见问题主要就在parse_str上了,它是PHP自带的一个函数,作用是将浏览器返回的 GET 方法的 QUERY_STRING 字符串解析,返回的变量名及值就依 QUERY_STRING 的名称及值,例如:

<?php
$str = "first=value&second[]=this+works&second[]=another";
parse_str($str);
echo $first;      // 显示出 "value" 字符串
echo $second[0];  // 显示 "this works" 字符串
echo $second[1];  // 显示 "another" 字符串
?>

OK,问题找到了,也就好解决了:

方法一:给$fileurl加上丢失的参数
parse_str($auth);
//获取真实fileurl
if($resid!="" && $fileid!="")
{
    $fileurl = $fileurl."&resid=".$resid."&fileid=".$fileid;
}

方法二:用substr对字符串进行截取,提取出地址,弥补方法一不具通用性的不足
parse_str($auth);
//获取真实fileurl
$urlstart = strpos($auth,"&fileurl=");
$urlend = strpos($auth,"&starttime=");
$fileurl = substr($auth,$urlstart+9,$urlend-$urlstart-9);


评论: 0 | 引用: 0 | 查看次数: 3919
发表评论
登录后再发表评论!