XF 2.0 Abstracted to absolute path

_PkZ_

Active member
Hi,
how can i get absolute path for abstracted paths like this: "internal-data://direcory/file.txt"?
 
It's not really possible. The thing to bear in mind is that the actual file may be hosted off-site so there's a good possibility that wherever it resolves to isn't useful.

Presumably you're wanting to do something to the file locally and perhaps write it back. In which case you'd do this:
PHP:
$tempFile = \XF\Util\File::copyAbstractedPathToTempFile('internal-data://direcory/file.txt');
$fp = fopen($tempFile, 'a');
fwrite($fp, 'Hello world!');
fclose($fp);
\XF\Util\File::copyFileToAbstractedPath($tempFile, 'internal-data://direcory/file.txt');
 
Thank you for your answer.
What i am trying to do is some "cleanup" when user are deleting a post and then i am trying to delete files in the internal-data path.
I tried to use $this->App()->fs()->delete("internal-data://some-data/1/2/1_2_*") but looks like wildcards are not allowed here and i get "file not found" error.

Any ideas on how to do this are welcome.

I want to use the internal-data abstraction because its an addon and i obviously doesnt know the absolute path in the final installation.
 
Wildcards wouldn't be possible as such, but you can use the Flysystem manager to list the contents of a directory, so you could do something like this:
PHP:
$contents = \XF::app()->fs()->listContents('internal-data://some-data/1/2');
foreach ($contents AS $content)
{
   if ($content['type'] != 'file')
   {
      continue;
   }

   if (strpos($content['filename'], '1_2_') === 0)
   {
      \XF::app()->fs()->delete('internal-data://' . $content['path']);
   }
}
 
Back
Top Bottom