Page 1 of 1

convert download.asp to download.php

Posted: Wed Mar 12, 2014 9:26 pm
by weixin268
convert download.asp to download.php, converted to get date and topic, but cannot get the filename to down?

download.asp

Code: Select all

sqlString = "SELECT * FROM upload ORDER BY uploaddate DESC"
set rs = conn.execute(sqlString)

Do While Not rs.EOF
Response.Write("<p><font size=""2"" face=""Times new roman"">")
Response.Write(rs("uploaddate"))
Response.Write(", ")
Response.Write(rs("topic"))
Response.Write(" <a href=""upload/" & rs("filename") & """ target=""_blank"">(Download)</a></font></p>" )
Response.Write(vbCrLf)
rs.movenext()
Loop

list.php
$sql = "SELECT date_format(uploaddate,'%c/%e/%y') as formatted_date, topic, filename from upload order by uploaddate desc";

        $result = mysql_query($sql);
        while($row = mysql_fetch_row($result))
        {
                 echo "$row[0],$row[1],<a href=\"download.php?filename=".urlencode($row[2])."\">(Download)</a><br><br>";
  }

Code: Select all

download.php
$filename=$_GET['filename'];
header('content-type:application/pdf');  
header('content-disposition:attachment; filename='.$filename); 
readfile("upload/".$filename);

Re: convert download.asp to download.php

Posted: Wed Mar 12, 2014 9:46 pm
by Christopher
Try a space between "content-disposition: attachment;" and you might want to add a:

header('Content-Length: ' . filesize("upload/".$filename));

Re: convert download.asp to download.php

Posted: Wed Mar 12, 2014 10:03 pm
by weixin268
<?php
$filename=$_GET['filename'];
header('content-type: application/pdf');
header('content-disposition: attachment;' filename=.$filename);
header('Content-Length: ' . filesize("upload/".$filename));
readfile("upload/".$filename);
?>

but still cannot, the link is http://www.mydomain.com/download.php?filename=

Re: convert download.asp to download.php

Posted: Thu Mar 13, 2014 10:07 am
by Christopher
Have you checked the error logs? Perhaps there is output occurring before this code that prevents headers from being sent?

Re: convert download.asp to download.php

Posted: Thu Mar 13, 2014 10:57 am
by jangmi
You need exact path to the file