Jump to content

File Visibility problems


spelltwister

Recommended Posts

Hey all!  I have a page that looks at a users posted data and fetches a .txt file for them, I want to prevent users from navigating to the .txt file directly, but if i change security off of 755, I get an error saying permission to read file denied.

 

I'm reading the file and echoing it back because the requesting application is a C# app using HttpWebRequest.  If there's a better way to do that, I'm all ears.

 

Here's the php code up:

 

<?php

$game = $_POST['gameNum'];
$player = $_POST['player'];
$file = $_POST['file'];

include('db.php');

if($file=="p"){
    $path = "/pathToFiles/$player.txt";
    getFileByPath($path);
}elseif($file=="setup"){//get setup file
  $path = "pathToFiles/setup.txt";
  getFileByPath($path);
}

function getFileByPath($path){
  $fp = fopen($path, 'r');// <------------ERROR: permission denied unless 755 :/
  if($fp){
    while(!feof($fp)){
      $buffer = fgets($fp, 4096);
      echo $buffer;
    }
    fclose($fp);
  }else{
    echo "Could not open file";
  }
}
?>

 

If I leave the file as 755, then anyone on the internet can view it by going to mydomain.com/pathToFiles/setup.txt and that'd be terrible ;D

 

Thanks for any help!

 

Mike

Link to comment
https://forums.phpfreaks.com/topic/171100-file-visibility-problems/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.