Changing upload dir for file field

Support General Changing upload dir for file fieldResolved

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #22760
    AshAsh
    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)

    #22762
    Long NguyenLong 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
    AshAsh
    Participant

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

    #22765
    Long NguyenLong Nguyen
    Moderator

    Hi,

    If you use the MB 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
    AshAsh
    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 NguyenLong 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
    AshAsh
    Participant

    Thank you.

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

    #22788
    Long NguyenLong 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 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.