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
weixin268
Forum Newbie
Posts: 15 Joined: Mon Feb 17, 2014 12:53 am
Post
by weixin268 » Wed Mar 12, 2014 9:26 pm
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);
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Wed Mar 12, 2014 9:46 pm
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
Post
by weixin268 » Wed Mar 12, 2014 10:03 pm
<?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=
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Thu Mar 13, 2014 10:07 am
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
Post
by jangmi » Thu Mar 13, 2014 10:57 am
You need exact path to the file