yobo Posted June 29, 2011 Share Posted June 29, 2011 Hey all, this kinda relates to my upload script problem but in some what way different I have now created a download script a small one that pulls the details of the files that where uploaded and places them with a link in a html table, now it creates the link ok but when I click the link nothing happens? <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>View File</title> <style type="text/css" title="text/css" media="all"> .error { font-weight: bold; color: #C00 } </style> </head> <body> <p>Click a file to download</p> <table align="center" cellspacing="5" cellpadding="5" border="1"> <tr> <td align="center"><b>File Name</b></td> <td align="center"><b>File Size</b></td> </tr> <?php /** * @author ohyeah * @copyright 2011 */ $dir = 'C:/wamp/uploads/'; $files = scandir($dir); foreach($files as $filedownload){ if(substr($filedownload, 0, 1) != '.'){ $file_size = round((filesize("$dir/$filedownload")) / 1024) . "kb"; $filedownload = urlencode($filedownload); echo "\t<tr> \t\t<td><a href=\"$dir$filedownload\">$filedownload</a></td> \t\t<td>$file_size</td> \t</tr>\n"; } } ?> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/240718-download-link-problem/ Share on other sites More sharing options...
fugix Posted June 29, 2011 Share Posted June 29, 2011 I beleive it is because you have two variables next to each other in your script. what does a "view source" show your href to be? Quote Link to comment https://forums.phpfreaks.com/topic/240718-download-link-problem/#findComment-1236415 Share on other sites More sharing options...
fugix Posted June 29, 2011 Share Posted June 29, 2011 try this <?php /** * @author ohyeah * @copyright 2011 */ $dir = 'C:/wamp/uploads/'; $files = scandir($dir); foreach($files as $filedownload){ if(substr($filedownload, 0, 1) != '.'){ $file_size = round((filesize("$dir/$filedownload")) / 1024) . "kb"; $filedownload = urlencode($filedownload); echo "\t<tr> \t\t<td><a href=\"{$dir}{$filedownload}\">$filedownload</a></td> \t\t<td>$file_size</td> \t</tr>\n"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/240718-download-link-problem/#findComment-1236417 Share on other sites More sharing options...
yobo Posted June 29, 2011 Author Share Posted June 29, 2011 Hey all this is my source html source code that is <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>View File</title> <style type="text/css" title="text/css" media="all"> .error { font-weight: bold; color: #C00 } </style> </head> <body> <p>Click a file to download</p> <table align="center" cellspacing="5" cellpadding="5" border="1"> <tr> <td align="center"><b>File Name</b></td> <td align="center"><b>File Size</b></td> </tr> <tr> <td><a href="C:/wamp/uploads/101_LPIC1_Mega_Guide.zip">101_LPIC1_Mega_Guide.zip</a></td> <td>753kb</td> </tr> <tr> <td><a href="C:/wamp/uploads/Blue+hills.jpg">Blue+hills.jpg</a></td> <td>28kb</td> </tr> <tr> <td><a href="C:/wamp/uploads/Symfony2-QuickTour.pdf">Symfony2-QuickTour.pdf</a></td> <td>131kb</td> </tr> <tr> <td><a href="C:/wamp/uploads/Winter.jpg">Winter.jpg</a></td> <td>103kb</td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/240718-download-link-problem/#findComment-1236418 Share on other sites More sharing options...
xyph Posted June 29, 2011 Share Posted June 29, 2011 A local link will not work in most browsers Try $dir_uri = 'file:///C:/wamp/uploads/'; Then use <a href=\"$dir_uri$filedownload\"> You need $dir for the filesize() call still though. Quote Link to comment https://forums.phpfreaks.com/topic/240718-download-link-problem/#findComment-1236421 Share on other sites More sharing options...
PFMaBiSmAd Posted June 29, 2011 Share Posted June 29, 2011 Links (download or any other kind) are URL's. You cannot put the C:/wamp (which is a file system path) into a URL. Quote Link to comment https://forums.phpfreaks.com/topic/240718-download-link-problem/#findComment-1236422 Share on other sites More sharing options...
fugix Posted June 29, 2011 Share Posted June 29, 2011 you will need to move your images into your server directory Quote Link to comment https://forums.phpfreaks.com/topic/240718-download-link-problem/#findComment-1236423 Share on other sites More sharing options...
yobo Posted June 29, 2011 Author Share Posted June 29, 2011 you will need to move your images into your server directory thanks all for your help and PFMaBiSmAd thanks for clearing that up for me Quote Link to comment https://forums.phpfreaks.com/topic/240718-download-link-problem/#findComment-1236433 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.