• Good evening, I would like to ask the community and users more experienced than me how to show a file size and/or file extension in Gutenberg’s “File” block. Unfortunately from the default settings this is not possible and I can’t find any suitable plugins that “enhance” the block in question. I also hope for future updates. Maybe even an update that shows a nice “file system” style file extension icon. Thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    You would like to see this just as useful information? You are not talking about adding other registered sizes to a block’s image size selection are you? I can imagine how such information is useful, but altering the related metabox code isn’t trivial.

    However, the information you seek is just a couple clicks away. For original file data, click “Replace”, then “Open in Media Library”. The file’s path and thus extension is visible after the first click, but it’s typically scrolled out of view. You don’t need to actually replace the image if you just want to look at its data. If you’re after the file data for the image size actually in use, use your browser’s element inspector tool. Right click, pick “Inspect” or equivalent function. Hover over the resulting image URL to see its data.

    If we were to alter the metabox to display such information, for what image would it be for? The original or the size actually in use? Both? Bear in mind we would like to keep meta boxes as clean and uncluttered as possible.

    Thread Starter pizienolamitica

    (@pizienolamitica)

    Thank you for your reply, maybe I didn’t explain myself well.

    So:
    when I write in backend, using Gutenberg, and select the “file block”, WordPress makes me choose a “file” to add to the block.
    So I choose the file and wait for it to load. So I publish the article and users can download the file by clicking on the “Download” button.

    I would like users who visit the site (and not me on the backend) to be able to see, next to the “Download” button, how many MB (or Kbytes) that file takes up. And I would hope that users could have a preview of the file extension (this is quite different from writing everything by hand in the text block). I would like the “file size visible to users” option to be enabled by default so I don’t have to waste my time and edit everything by hand.

    Thank you so much!

    Moderator bcworkz

    (@bcworkz)

    For appearance on the front end you’d need to modify the template which is outputting the download button.

    You can get the file’s extension with pathinfo( $filename, PATHINFO_EXTENSION )
    Get the file’s size with filesize( $filename )
    In both cases $filename should be the full absolute path to the file. You can get the full path to an attached file with get_attached_file( $attachment_id ) provided the attachment ID is available.

    Thread Starter pizienolamitica

    (@pizienolamitica)

    Thank you for your response.
    Unfortunately, I am not very familiar with these procedures and don’t really know how to do it.
    I was hoping there would be a way to ask for it maybe in the next Gutenberg updates, as an extension of the basic “file block” functionality in the settings of the same from the regular text editor.
    Could you describe to me the above steps?
    And could you kindly tell me if there is a plugin that, without entering code (which for the likes of me is always scary), could show the size of a file uploaded with the file blocker?
    Thanks for the invaluable help!

    Moderator bcworkz

    (@bcworkz)

    I’m sorry, my bad. I somehow had a different paradigm in mind that is definitely not the file block. The content you want can be injected via JavaScript. I’m unsure what JS functions are available to get file size. The file’s extension can be extracted with string manipulation, though there may be an easier way.

    If you want to formally submit a suggestion for the Gutenberg devs, raise a feature request issue over at their GitHub site. (free registration required)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show “File size” and “extention” on Gutenberg File Block’ is closed to new replies.