convert download.asp to download.php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
weixin268
Forum Newbie
Posts: 15
Joined: Mon Feb 17, 2014 12:53 am

convert download.asp to download.php

Post 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);
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: convert download.asp to download.php

Post by Christopher »

Try a space between "content-disposition: attachment;" and you might want to add a:

header('Content-Length: ' . filesize("upload/".$filename));
(#10850)
weixin268
Forum Newbie
Posts: 15
Joined: Mon Feb 17, 2014 12:53 am

Re: convert download.asp to download.php

Post 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=
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: convert download.asp to download.php

Post by Christopher »

Have you checked the error logs? Perhaps there is output occurring before this code that prevents headers from being sent?
(#10850)
jangmi
Forum Newbie
Posts: 11
Joined: Sat Mar 08, 2014 7:39 am

Re: convert download.asp to download.php

Post by jangmi »

You need exact path to the file
Post Reply