I need the option to show other people who are not programmers the variety of files they could download from the FTP server folder (I use WinSCP)
Now the problem with the code is that if you write one specific file name in the PHP script, you can download it without a problem. But what i need is for them to upload(which works fine) but also for them to be able(some other time or someone else) to choose from the previous uploaded files and to download that specific one that they selected.
So the precise thing we need is to open the folder, show all the files in there and then to be able to choose from one of those files and download it.
Does anyone know how to solve this or is it even possible?
<?php
//uploads is the folder name at the ftp server
if ($handle = opendir('uploads/')) {
while (false !== ($entry = readdir($handle)))
{
//
if ($entry != "." && $entry != "..") {
//download.php is the file where we write the code
echo "<a href='download.php?file=".$entry."'>".$entry."</a>
";
}
}
closedir($handle);//
}
// we are trying to get the files by listing it with .$file variable
$file = basename($_GET['file']);
$file = 'uploads/'.$file;
//here we are
$mimi = $file;
if(!mimi_exists($file)){ // file does not exist
die('file not found');
} else {
header("Cache-Control: public"); //
header("Content-Description: File Transfer");//
header("Content-Disposition: attachment; filename=$file");//
header("Content-Type: application/zip");//
header("Content-Transfer-Encoding: binary");//
// read the file from disk
readfile($file);
}
?>
With this previous code, the file names (from the folder) are listed and shown as links but there is no action when we click on them.