I have a page, but I do not want it when I click on files of type .txt to download, instead of displaying them. I'm developing this page in PHP.
I have seen some script on the WEB, however it is forcing the download of .txt files without it being at least clicked on.
Here is the code I'm doing:
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9"/>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>FTP</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
if(isset($_GET['path']))
$dir = $_GET['path'];
else
$dir = '..'. DIRECTORY_SEPARATOR .'ftp';
foreach (new DirectoryIterator($dir) as $file) {
if (!$file->isDot()) {
if ($file->isDir()) {
echo '<div class="pastas">';
echo '<a href="index.php?path='.$dir. DIRECTORY_SEPARATOR .$file.'"><img src="icones/archive.ico" width="30px" height="30px"/></a>' . $file->getBaseName();
echo '</div>';
} else {
switch($file->getExtension()) {
case 'txt':
echo '<a href=""><img src="icones/text.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
break;
case 'jpg':
echo '<a href=""><img src="icones/jpg.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
break;
case 'gif':
echo '<a href=""><img src="icones/jpg.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
break;
case 'docx':
echo '<a href=""><img src="icones/doc.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
break;
case 'doc':
echo '<a href=""><img src="icones/doc.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
break;
case 'pdf':
echo '<a href=""><img src="icones/pdf.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
break;
case 'ppt':
echo '<a href=""><img src="icones/ppt.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
break;
case 'rar':
echo '<a href=""><img src="icones/rar.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
break;
case 'zip':
echo '<a href=""><img src="icones/zip.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
break;
case 'avi':
echo '<a href=""><img src="avi.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
break;
case 'mp3':
echo '<a href=""><img src="icones/mp3.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
break;
case 'wmv':
echo '<a href=""><img src="icones/wmv.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
break;
case 'exe':
echo '<a href=""><img src="icones/exe.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
break;
default:
echo '<a href=""><img src="icones/default.ico" width="30px" height="30px" /></a>'.$file->getBaseName();
}
}
}
}
?>
</body>