Issue Bug Closed

#99404Invalide relative path given by getPublicUrl()

Florian Rival 12/21/22, 11:54 updated 01/05/23, 14:04

Description

On a FileReference, if you try to get the public Url with :

$myFile->getOriginalResource()->getPublicUrl()

you get a relative URL like this :

> ‘/uploads/tx_myext/MyTestFile.pdf’

but this URL is prefixed with a slash and then cannot be used with functions like fopen()

Before TYPO3 V11, the method getPublicUrl() return a path like this :

> ‘uploads/tx_myext/MyTestFile.pdf’

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 3

  1. Christoph Lehmann commented 12/23/22, 21:18

    If you wanna work with a file in the filesystem, then you can do it like this

    // Path to local file (either original or copied to some temporary local location
    $filePath = $file->getStorage()->getFileForLocalProcessing($file);

    getPublicUrl() returns a publicly accessible URL for this file and it is not meant to be used in filesystem context.

    Is it okay to close the issue for this reason?

  2. Florian Rival commented 12/27/22, 09:26

    Thanks for you answer.

    In my case, it works with that :

    $myFile->getOriginalResource()->getForLocalProcessing();

    You can close this issue.

  3. Chris Müller changed status New Closed 01/05/23, 14:04