• Resolved Wills1971

    (@wills1971)


    Hello,

    I’m using CFS for contributor users to upload .zip file with their art, .zip file which is downloadable from front end (blog post).

    1. Is there any way I can limit file type to .zip (compressed files)
    2. Is there any way I can show file size of uploaded .zip file as info at front end, some files could be over 50 MB heavy for download.

    Thanks in advance!

    https://www.ads-software.com/extend/plugins/custom-field-suite/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Matt Gibbs

    (@mgibbs189)

    Hi,

    1. CFS uses the default WP media uploader, so I’m not 100% sure if it supports this feature. I’ve added a GitHub task to investigate further – https://github.com/mgibbs189/custom-field-suite/issues/82

    2. Yes. First, set the field’s “Return Value” option to “Attachment ID”. Then, you can use something like this:

    $attachment_id = $cfs->get('my_file_field');
    $bytes = filesize(get_attached_file($attachment_id));
    echo size_format($bytes);
    Thread Starter Wills1971

    (@wills1971)

    Hi and thank you for the prompt answer.

    Regarding 2.:
    I need to output attachment url (for file download purpose) and I wish to also output file size. If I set the field’s “Return Value” option to “Attachment ID” then I could not get URL, right?

    Thanks again!

    Plugin Author Matt Gibbs

    (@mgibbs189)

    You can get the URL from the attachment ID using the wp_get_attachment_url function.

    https://codex.www.ads-software.com/Function_Reference/wp_get_attachment_url

    Thread Starter Wills1971

    (@wills1971)

    GREAT!
    For the reference for non coders like me, I’ve just added this to code above:
    &attachment_url = wp_get_attachment_url($attachment_id);
    and output url:
    echo &attachment_url;

    everything works great now.

    Regarding restricting file uploads to certain file types. I’m sure that feature can be added, Attachments plugin from Jonathan Christopher support restricting file uploads to certain file types and works with WP 3.5

    Plugin Author Matt Gibbs

    (@mgibbs189)

    Regarding restricting file uploads to certain file types. I’m sure that feature can be added, Attachments plugin from Jonathan Christopher support restricting file uploads to certain file types and works with WP 3.5

    Hey, I just spoke with Jonathan. It appears as though you can restrict uploads by category (audio, video, application), but not necessarily by specific file extension (zip, pdf).

    I’ll post any further updates into the GitHub task.

    Matt

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Getting uploaded file size’ is closed to new replies.