Tenho uma página, mas não quero que quando clique em arquivos do tipo .txt faça download, ao invés de exibi-los. Estou desenvolvendo essa página em PHP.
Vi alguns script na WEB, porém ele está forçando o download de arquivos do tipo .txt sem que ele seja ao menos clicado.
Segue o código que estou fazendo:
<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>