|
|
@ -3,6 +3,8 @@
|
|
|
|
namespace DataAccess\Files;
|
|
|
|
namespace DataAccess\Files;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use BusinessLogic\Exceptions\ApiFriendlyException;
|
|
|
|
|
|
|
|
|
|
|
|
class FileReader {
|
|
|
|
class FileReader {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param $name string - The file name (including extension)
|
|
|
|
* @param $name string - The file name (including extension)
|
|
|
@ -13,6 +15,11 @@ class FileReader {
|
|
|
|
function readFromFile($name, $folder) {
|
|
|
|
function readFromFile($name, $folder) {
|
|
|
|
// __DIR__ === '/{ROOT}/api/DataAccess/Files
|
|
|
|
// __DIR__ === '/{ROOT}/api/DataAccess/Files
|
|
|
|
$location = __DIR__ . "/../../../{$folder}/{$name}";
|
|
|
|
$location = __DIR__ . "/../../../{$folder}/{$name}";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!file_exists($location)) {
|
|
|
|
|
|
|
|
throw new ApiFriendlyException("The file '{$name}' does not exist on the server", "File Not Found", 404);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$fileContents = file_get_contents($location);
|
|
|
|
$fileContents = file_get_contents($location);
|
|
|
|
|
|
|
|
|
|
|
|
if ($fileContents === false) {
|
|
|
|
if ($fileContents === false) {
|
|
|
|