Jump to content

Download Link problem


yobo

Recommended Posts

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>

Link to comment
Share on other sites

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";
    }
}

?>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.