douyakan8924 2012-12-04 10:37
浏览 39
已采纳

pdf文件下载链接无法在php中工作[关闭]

I've been using this site to look for answers but I can't find any that may help so I decided to create an account and ask myself.

Here is a link to the website that I'm working on http://www.h-elpsystems.co.uk/index.php. It's a database driven website which allows users to download files. Now I was working on one page of the website (as far as I'm aware I didn't touch any of the code that used the download code) and now all of a sudden the downloads don't work.

The downloads are located on the "employment law page" at the bottom. When you click on the link to download a file it just sends the user to the same page only with a # in the URL at the end.

I'm not sure which bit of code to upload (I'm new to php) but if someone will let me know which is needed I'll upload it.

Thanks for any help in advance.

PS here is the code that I'm using for the download. (note I didn't create the code, I just edited a page or two and the downloads seemed to have stopped working for some reason.)

<?
// Define the path to file
$file = "membersfiles/".$_GET['ID'];

if(!file)
{
 // File doesn't exist, output error
 die('file not found');
}
else
{
 // Set headers
 header("Cache-Control: public");
 header("Content-Description: File Transfer");
 header("Content-Disposition: attachment; filename=$file");
 header("Content-Type: application/zip");
 header("Content-Transfer-Encoding: binary");

 // Read the file from disk
 readfile($file);
 }
 ?>

 <!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>Download file</title>
 </head>

 <body>
 </body>
 </html>

Also below is the code for the employment page. (Sorry I'm new to this forum so didn't really know what to include in the question)

<?
session_start;
include("../Functions.inc");
$ID=PageID(substr(dirname($_SERVER['PHP_SELF']), 1, strlen(dirname($_SERVER['PHP_SELF']))));

?>



<!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=iso-8859-1" />
<title><? echo PageTitle($ID);?></title>
<meta name="keywords" content="<? echo PageKeywords($ID);?>" />
<meta name="description" content="<? echo PageDescription($ID);?>" />
<meta name="robots" content="index,follow" />


<link href="../mainstyles.css" rel="stylesheet" type="text/css" media="screen" />

</head>

<body>

<div id="wrapper">

<div id="leftcolumn"><div id="mainnav"><img src="../media/logo.gif" alt="H-elp Systems" /><? include("../Left-Links.inc"); ?>
<a href="mailto:info@h-elpsystems.com" id="emailbutton" ><span>click here to email us</span></a>
<img src="../media/navfooter.gif" alt="Help Systems" /></div>
</div>


<div id="centercolumn">
<div id="topnav">
<? include("../Top-Links.inc"); ?>
</div>

<div id="content">
<img src="../media/headers/<? echo PageTitle($ID);?>.jpg" alt="" />
<img src="../media/splashtext/<? echo PageTitle($ID);?>.gif" alt="When it come to employment you need h-elp systems" /><a href="#" id="phonelink" ><span>0121 635 5870</span></a>
<img src="../media/hr450.gif" alt="Help Systems" />
<div id="contentcopy">
<h1><? echo PageSplash($ID);?></h1>
<? echo PageContent($ID);?>

<?
    $query = "SELECT * FROM `Files` WHERE  `Employment`=1";    
    $result = mysql_query($query) or die ("Failed To get member files!"); 

    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

        print("<img src=\"../media/hr450.gif\"/><br><a href=\"#\" onclick=\"javascript:downloadwindow('../Download.php?ID=".$line['URL']."');\">".$line['URL']."</a>");

    }
?>
</div>
<img src="../media/hr450.gif" alt="Help Systems" />

<div id="footer">
<p>RJS Management Services Ltd   Concorde House   Trinity Park   Solihull   B37 7UQ<br />
Tel.+44 (0)121 635 870   Email. <a href="mailto:action@h-elpsystems.com">action@h-elpsystems.com</a></p>
</div>
</div>

</div>
<div id="rightcolumn">

<? 
$query = "SELECT * FROM `News` ORDER BY `Date` DESC limit 0, 4";    
$result = mysql_query($query) or die ("Failed To get latest news!"); 

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $ShortContent=substr($line['Content'],0,175);
    print("<h2>".$line['Title']."</h2>".$ShortContent."...<p class=\"small\">".$line['Date']."</p><a href=\"../News.php?Article=".$line['ID']."\" class=\"clickformore\" ><span>click here for more</span></a><img src=\"../media/hr.gif\" alt=\"H-elp\" />");

} 
 ?>

 </div>


 </div>
 </body>
 </html>


 <?
 //Close any open connetions
 mysql_close;
 ?>

edit: I've tried everyone's answers and they seem to work in some form but for some reason when i upload the changed code to the server it seems to bring up a blank page when ever I click on the employment law page. Now I don't know if I'm saving it wrong or uploading it wrong or if something else is wrong.

  • 写回答

4条回答 默认 最新

  • douxin2002 2012-12-04 10:43
    关注

    The first thing to do, is add the code from the employment page that produces the download links. This will give us an idea of where the download is coming from in the website.

    Right now it looks like the problem is the download link itself; all the links simply point to the employment page with a hashtag but no variable after the hashtag. So, unless a form is supposed to submit the data onclick (which is unlikely in the extreme), then the download URLs are incorrect.

    So add the code from the employment page that displays the download links and we can go from there.


    The problem is definitely the link on the employment page. I suspect that a file being included has been moved or modified.

    Check that include("../Functions.inc"); is still in that path relative to the employment page (i.e. one folder up from the employment page).

    Next thing to do if that's not the problem, in my opinion, would be to modify the code. It's not really necessary to be using seperate javascript code to open the download in a new window.

    So change this line on the employment page:

    print("<img src=\"../media/hr450.gif\"/><br><a href=\"#\" onclick=\"javascript:downloadwindow('../Download.php?ID=".$line['URL']."');\">".$line['URL']."</a>");
    

    To this:

    print("<img src=\"../media/hr450.gif\"/><br><a href=\"../Download.php?ID=".$line['URL']."\" target=\"_blank\">".$line['URL']."</a>");
    

    I hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码