Hi all,
I have a file download counter on my website, here, that I am playing around with.
The files are stored in a folder on my server and their filenames are used to populate a mysql database.
What I would dearly like is for the filename without it's extension to be displayed in the table on my webpage but I can't seem to figure it out.
I have tried a few methods but have not got anywhere.
I can't seem to get anything to work when I replace the $val variable in the href statement.
I would be grateful for any pointers here.
Many thanks..,
K.
<?php
// Error reporting:
error_reporting(E_ALL^E_NOTICE);
// Including the DB connection file:
require 'dlc_connect.php';
$extension='';
$files_array = array();
/* Opening the thumbnail directory and looping through all the thumbs: */
$dir_handle = @opendir($directory) or die("There is an error with your file directory!");
while ($file = readdir($dir_handle))
{
/* Skipping the system files: */
if($file{0}=='.') continue;
/* end() returns the last element of the array generated by the explode() function: */
$extension = strtolower(end(explode('.',$file)));
/* Skipping the php files: */
if($extension == 'php') continue;
$files_array[]=$file;
}
/* Sorting the files alphabetically */
sort($files_array,SORT_STRING);
$file_downloads=array();
$result = mysql_query("SELECT * FROM download_manager");
if(mysql_num_rows($result))
while($row=mysql_fetch_assoc($result))
{
/* The key of the $file_downloads array will be the name of the file,
and will contain the number of downloads: */
$file_downloads[$row['filename']]=$row['downloads'];
}
?>
<link rel="stylesheet" type="text/css" href="****.css" />
<script type="text/javascript" src="****.js"></script>
<script type="text/javascript" src="****.js"></script>
<center>
<table>
<tr>
<td>File Name</td>
<td>Downloads</td>
</tr>
<?php
foreach($files_array as $key=>$val)
{
echo '
<tr>
<td><a href="dlc_download.php?file='.urlencode($val).'">'.$val.'</a></td>
<td><span class="download-count">'.(int)$file_downloads[$val].'</span></td>
</tr>';
}
?>
</table>
</center>