【问题标题】:downloading not working on my mp3 website [duplicate]下载无法在我的 mp3 网站上运行 [重复]
【发布时间】:2015-04-27 12:16:44
【问题描述】:

我有 mp3 网站,当我点击下载时出现类似这样的错误,所以我可以解决这个问题,请帮帮我,我正在等你们,所以请给我打电话,我也删除了那个空间,但如果完整代码仍然会发出这个问题当我点击下载它的重定向到主页时,这是一个不同的问题,之前我没有解释完整现在这里也充满了完整的代码

PHP 解析错误:语法错误,第 42 行 /home/xxx/public_html/xxxx/xxxx/themes/xxxx/functions/source/download_mp3.php 中的意外 '$title' (T_VARIABLE)

<?php
require_once('../../../../../wp-load.php');
if(isset($_REQUEST['filename'])) {
    $filename = $_REQUEST['filename'];
} else {
    echo '<p>No id passed in</p>';
    exit;
}

function checkRemoteFile($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
// don't download content
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch)!==FALSE){
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if (($code == 301) || ($code == 302)) {
        return false;
    }else{
        return true;
    }
}else{
    return false;
}
}
$checkMp3 = checkRemoteFile( base64_url_decode( $filename ) );
$title=$_GET['ref'];
$mp3file = base64_url_decode( $filename );
if($checkMp3){
?>
<html>
<head>
<title>Download Mp3</title>
</head>
<body>
<div class="downButtons" style="margin:5px">
<b class="red">Choose a server to download your song!</b>
<br><br><a rel="nofollow" target="_blank" title="Right Click to Download Mp3"class="dr dss" href="/download?mp3=<?php echo $mp3file;?>&title=<?php echo $title;?>"><img style="max-height:60px"src="http://ppp.com/download.jpg"></a>
</body>
</html>
<?php
}
else
{
echo '<div style="font-size:11px;text-align: center;color: black;">file not found, try other download link</div>';    
}
?>

这是第 42 行错误代码

 <br><br><a rel="nofollow" target="_blank" title="Right Click to Download Mp3"class="dr dss" href="/download?mp3=<?php echo $mp3file;?>&title=<?php echo $title;?>"><img style="max-height:60px"src="http://ppp.com/download.jpg"></a>

【问题讨论】:

  • 为了防止错误尝试使用 $title=isset( $_GET['ref'] ) ? $_GET['ref'] : '';
  • 请不要在 cmets 中转储代码。使用附加信息更新您的原始帖子。

标签: php download mp3


【解决方案1】:

只有在没有设置get参数的情况下才会出现这个错误。

并且您应该始终检查获取数据是否确实存在并且不为空。

代替:

$title=$_GET['ref'];

你应该有类似的东西:

if (isset($_GET['ref']) && !empty($_GET['ref'])) {
    $title = $_GET['ref'];
}

编辑:我看到您也回显了 $title,因此如果您没有收到任何获取数据,您可以将标题设置为空白。

像这样:

if (isset($_GET['ref']) && !empty($_GET['ref'])) {
    $title = $_GET['ref'];
} else {
    $title = "";
}

或者你可以像这样缩短它:

$title = (isset($_GET['ref']) && !empty($_GET['ref']) ? $_GET['ref'] : '');

【讨论】:

  • 不工作,我试了一下,但点击下载按钮时仍然出现同样的错误,它会重定向到主页
  • 嗯?你仍然得到这个确切的错误信息吗? PHP 解析错误:语法错误,第 42 行 /home/xxx/public_html/xxxx/xxxx/themes/xxxx/functions/source/download_mp3.php 中的意外“$title”(T_VARIABLE)
  • 是的,当点击下载按钮时,它会重定向到主页,为什么它实际上没有下载,我是从 soundcloud 上的 api 下载的
  • 是的,是的,错误信息是否完全相同?我不知道 $_REQUEST['filename'] 包含什么,所以我无法为您提供实际的下载部分。
  • 我可以知道你的 Skype id 吗?请解决这个问题
猜你喜欢
  • 2017-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-06
  • 1970-01-01
  • 1970-01-01
  • 2020-07-22
  • 1970-01-01
相关资源
最近更新 更多