black friday sale

Custom Fields
Re-Envisioned
Support General Changing upload dir for file field

  • Creator
    Topic
  • #22760
    Resolved Ash
    Participant

    How do I change upload directory for file field?

    I tried upload_dir hook but doesn’t work.
    (It works on Media Library though)

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #22762
    Long Nguyen
    Moderator

    Hi,

    The field file support uploading to the custom folder, please follow this documentation for more information https://docs.metabox.io/fields/file/#upload-to-custom-folder.

    #22763
    Ash
    Participant

    So if I set it on the custom field setting screen,
    Would it be like this?
    https://share.getcloudapp.com/12urZ0AQ

    #22765
    Long Nguyen
    Moderator

    Hi,

    If you use the Meta Box Builder, please add the path of the folder. You can create a file test.php in the folder invoices for example and add this code to the file test.php

    <?php 
    echo __DIR__;

    Run the file in the URL http://site.com/wp-content/invoices/test.php. It will display the path to the folder, such as /var/www/wp-content/invoices, then add the path of the folder to the custom attribute. See my screenshot https://share.getcloudapp.com/OAuJevlg.

    #22776
    Ash
    Participant

    Thank you.
    I was able to set custom directory.

    one question. when I set custom directory, uploaded file won’t show up in Media Library.
    Is this what it is?

    I may be fine with this behavior though.

    #22780
    Long Nguyen
    Moderator

    Hi,

    The file saved in the custom folder won’t show on the Media Library. We also note about this case in the documentation.

    Unlike the normal case, where files are added to the WordPress Media Library, files uploaded to custom folders are not available in the Media Library. Thus, the data saved in the custom fields is file URL, not attachment ID.

    #22785
    Ash
    Participant

    Thank you.

    Is it possible to set custom directly for image/advanced image filed as well?

    #22788
    Long Nguyen
    Moderator

    Hi,

    The setting upload_dir only available for the field file. I’m going to create a feature request to support this setting for other upload fields.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.