Skip to content

When uploading file, height and width attributes not included in resulting tag. #4285

Closed

Description

@GaryReckard

Description of the problem
When using a textarea, and uploading an image, the resulting <img> tag does not include the width and height attributes. If you instead select an image from the File picker, it does include those attributes.

How To Reproduce
Steps to reproduce the behavior:

  1. Click file upload button on a Textarea field
  2. Select a upload directory
  3. Click 'Upload' button and find a file on your computer
  4. view resulting <img> tag, missing height and width
  5. Try the same process, but select existing image (even the one you just uploaded) and see width and height attribtutes in resulting tag

Environment Details:

  • Version: 7.4.9
  • PHP Version 8.2
  • MySQL Version 8

Possible Solution
Including 'file_hw_original' => $result['upload_response']['file_hw_original'], in the 'body' of the ajax response in Filepicker_mcp::ajaxUpload() seems to fix the issue for me.

Activity

  1. added
    Bug: UnconfirmedBug report that is not yet confirmed and/or is not reproducible.
    on May 1, 2024
  2. bryannielsen commented on May 8, 2024

    @bryannielsen
    Contributor

    @GaryReckard thanks for opening this issue!

    I think I'm doing something different in trying to recreate the problem. I was trying to follow your steps exactly but here's a recording if you don't mind taking a look and telling me where I've gone wrong that would be greatly appreciated!

  3. GaryReckard commented on May 8, 2024

    @GaryReckard
    ContributorAuthor

    Hi @bryannielsen
    Thanks for that screen recording! So, I'm not sure if it's because you don't have any images in your chosen upload directory, or if something is slightly different about our setups, but when I get to the part where I choose an "Upload Location" from the dropdown, I do not see the "Drop file(s) Here to Upload" drag target area thingymabob. I just see the list of files in that directory.
    And I've been clicking the "Upload" button in the top right. When I click that, it opens the native file browser, and once I select a file, it closes that file browser dialog, i see the file upload progress, and then the file manager modal closes itself automatically, and that is when I get the image tag, sans height and width attributes.

  4. bryannielsen commented on May 8, 2024

    @bryannielsen
    Contributor

    Oh interesting, I did try with the upload button and in a directory that had files but the behavior was the same for me. I've never seen the modal close itself after the upload so I wonder if we have some JS behaving differently. I'm using Chrome on a mac, what browser are you using? (fingers crossed it's different!)

  5. GaryReckard commented on May 17, 2024

    @GaryReckard
    ContributorAuthor

    Hi again @bryannielsen . Thanks again for your time on this. I'm also using Chrome (Version 124.0.6367.203 (Official Build) (arm64)) on a Mac (Ventura 13.2 (22D49)).
    I just confirmed that my system and theme ee directories have all the exact files from the EE 7.4.9 zip file.

    I tested with the drag-and-drop files method, and that does upload the file and leaves the file list modal up, and clicking on the file then closes the modal and adds the img tag (with width and height attributes). But my fix/hack I mentioned already addressed that with the button method of uploading for me, so that's all good.

    A separate issue that my client has identified is that, previously, on EE4, when uploading a file, you'd be presented with the file upload button, and also the input fields for "Description", "Credit", "Location", which they found useful to populate before adding the image to their entry. Now, in EE7, those fields do not show up when uploading an image, they have to go to their "Files" section, find the file, and edit it, to add those values.

  6. GaryReckard commented on May 17, 2024

    @GaryReckard
    ContributorAuthor

    Hi again @bryannielsen
    I just installed a fresh version of EE 7.4.9 locally, and tested this out, and still seeing the same behavior. From a 100% fresh install, I added a channel, and a textarea field to it with "Show File chooser" enabled. Added a file upload directory (adapter: local, allowed file types: image, default browser view: list).

    Then went to create an entry in that Channel, hit the file chooser button on my textarea. In the popup, chose my upload directory, then clicked the "Upload" button, chose a file, and it immediately closed the modal, and added the tag with no height or width attributes.

    Here is the fix that I've applied locally to get this to include those attributes in the img tag in /ee/ExpressionEngine/Addons/filepicker/mcp.filepicker.php:
    image

  7. bryannielsen commented on May 18, 2024

    @bryannielsen
    Contributor

    @GaryReckard thanks for taking the time to test on a fresh install and give me those detailed steps. I can reproduce this now and your fix looks good as well. Would you like to open a Pull Request with your change so that you can get credit for the work? We always want to encourage open source contributions and are extremely grateful for your time on this issue!

  8. added
    Bug: AcceptedBug has been confirmed, is reproducible, and ready to work on.
    and removed
    Bug: UnconfirmedBug report that is not yet confirmed and/or is not reproducible.
    on May 18, 2024
  9. added a commit that references this issue on May 18, 2024
    700057a
  10. added a commit that references this issue on May 21, 2024
    e636aca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug: AcceptedBug has been confirmed, is reproducible, and ready to work on.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions