最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Access Private Resource File - Stack Overflow

programmeradmin2浏览0评论

I am trying to read the mask.json from a site_package and use that to generate an api response using an extension like nnrestapi

this is the code i currently have

$filePath = "EXT:site_package/Configuration/Mask/mask.json";
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$file = $resourceFactory->retrieveFileOrFolderObject($filePath);
$fileContent = $file->getContents();
// do something with $fileContent

but I am getting this error

Tried to access a private resource file "EXT:site_package/Configuration/Mask/mask.json" from fallback compatibility storage. This storage only handles public files.

How can I access that file? Is there a better way? Maybe to edit the site_package directly?

I am trying to read the mask.json from a site_package and use that to generate an api response using an extension like nnrestapi

this is the code i currently have

$filePath = "EXT:site_package/Configuration/Mask/mask.json";
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$file = $resourceFactory->retrieveFileOrFolderObject($filePath);
$fileContent = $file->getContents();
// do something with $fileContent

but I am getting this error

Tried to access a private resource file "EXT:site_package/Configuration/Mask/mask.json" from fallback compatibility storage. This storage only handles public files.

How can I access that file? Is there a better way? Maybe to edit the site_package directly?

Share Improve this question asked Feb 7 at 7:51 Bernd StorathBernd Storath 31 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 2

There are several options:

  1. Move the file into a public area, like fileadmin or Resources/Public of your sitepackage (not recommended as "everybody" can access your Mask configuration and therefor can use the information for hacking). Be aware to edit the settings of mask to tell the system that the file is in a new location.
  2. Use a simple file_get_contents() to read the JSON file in the API and output it (best solution as you can secure your requests so not everybody can access it). You also can change / remove sensible information in this process
  3. Copy the file into a public area (your information wouldn't be up-to-date)

Would be nice to read why you want to access this file via API? What is the purpose? Maybe there is a much better way?

I solved it by using this code

$absolutePath = GeneralUtility::getFileAbsFileName('EXT:site_package/Configuration/Mask/mask.json');
$fileContent = file_get_contents($absolutePath);
发布评论

评论列表(0)

  1. 暂无评论