file_get_contents() a prod uploaded file? possible?

Created on 9 July 2019, almost 5 years ago
Updated 31 May 2024, 17 days ago

Sometimes we want to embed a file in the page e.g. SVG, so we use file_get_contents().

Is there a way to make it work with this module? public:// alter function? not sure?

recommendations?

✨ Feature request
Status

Active

Version

3.0

Component

Documentation

Created by

πŸ‡¦πŸ‡ΊAustralia silverham

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Even though D7 has been extended to 2025, think it's unrealistic that modules will continue to support also. So closing out old D7 tickets. If anyone feels super strongly about adding to D7 please reopen but the D7 module will be relatively unmanned.

  • Status changed to Active 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States ksenzee Seattle area

    I'm having this exact issue on 2.1.2. I have the following custom code:

    $svg_file = file_get_contents($file->getFileUri());
    

    The D10 equivalent of the D7 workaround from above ($file->createFileUrl();) no longer applies, since events have replaced the hook_file_url_alter() implementation. When you run file_get_contents() on a public:// uri, you end up in \Drupal\Core\StreamWrapper\LocalStream::stream_open(), which just calls fopen() and returns false if the file isn't there, without triggering any events. I'm coming up blank trying to think of a production-safe workaround.

  • πŸ‡ΊπŸ‡ΈUnited States ksenzee Seattle area

    (fixing version dropdown)

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave
Production build 0.69.0 2024