user2123427
user2123427

Reputation: 43

How to deny the web access to txt file?

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);

Upvotes: 1

Views: 177

Answers (1)

&#193;lvaro Gonz&#225;lez
&#193;lvaro Gonz&#225;lez

Reputation: 146460

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.

Upvotes: 1

Related Questions