1

how to deny access to txt, dont's show web browser name.txt file?

$filename = "/txt/name.txt";
$handle   = fopen($filename, 'r');
$data     = fread($handle, filesize($filename));
$rowsArr  = explodeRows($data);
for($i=0;$i<count($rowsArr);$i++) {
  $lineDetails = explode("|",$rowsArr[$i]);
  if ($kodas == $lineDetails[2]) {
    $link3=$lineDetails[4];
    echo "";
     } }
fclose($handle);
  • 1
    possible duplicate of [How to deny access to a file in .htaccess](http://stackoverflow.com/questions/11728976/how-to-deny-access-to-a-file-in-htaccess) – John Conde Jan 08 '14 at 16:24

1 Answers1

1

File names are nothing but strings:

if( substr($filename, -4)=='.txt' ){
    echo 'Access denied';
}

But if you're accepting file names from the user you should add further checks, esp. regarding paths.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360