Php 使用if语句选择标题
我正在尝试制作一个如下的下载页面:Php 使用if语句选择标题,php,forms,header,download,Php,Forms,Header,Download,我正在尝试制作一个如下的下载页面: <?php $filetype = $_POST['filetype']; echo "$filetype"; if( $filetype == '256mp3'){ header('Content-disposition: attachment; filename=mp3.html'); header('Content-type: text/html'); readfile('mp3.html'); } if($filety
<?php
$filetype = $_POST['filetype'];
echo "$filetype";
if( $filetype == '256mp3'){
header('Content-disposition: attachment; filename=mp3.html');
header('Content-type: text/html');
readfile('mp3.html');
}
if($filetype == 'apple lossless' ){
header('Content-disposition: attachment; filename=applelossless.html');
header('Content-type: text/html');
readfile('applelossless.html');
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
为什么这不起作用?标记前面没有空格,因为头语句前面有
echo$filetype
。如果要设置标题,则无法输出任何内容。如果你真的必须这样做,那么试着看看
另外,我没有得到您想要的结果,之前您已经使用readfile()
输出了html,但后来您正在输出另一个
,这是有意的吗?删除此选项
回显“$filetype” 我发现您的代码存在两个潜在问题:
- 行
echo“$filetype”代码>将数据写入客户端,导致发送头,然后对
头()的后续调用失败
- 您可能需要调用
exit每次调用
(假设readfile()
没有以readfile()
结束)后立即执行code>,以防止exit;
条件下的html发送到浏览器if()
if( $filetype == '256mp3'){
header('Content-disposition: attachment; filename=mp3.html');
header('Content-type: text/html');
readfile('mp3.html');
}
if($filetype == 'apple lossless' ){
header('Content-disposition: attachment; filename=applelossless.html');
header('Content-type: text/html');
readfile('applelossless.html');
}
?>
请单击左侧旁边的复选框,将其中一个答案标记为正确答案。然后删除这个答案。
if( $filetype == '256mp3'){
header('Content-disposition: attachment; filename=mp3.html');
header('Content-type: text/html');
readfile('mp3.html');
}
if($filetype == 'apple lossless' ){
header('Content-disposition: attachment; filename=applelossless.html');
header('Content-type: text/html');
readfile('applelossless.html');
}
?>