• Hello!
    I’m trying to follow this tutorial.
    But instead of using PDF I would like to use ZIP.

    I replaced this line:
    $supported_types = array('application/pdf');
    with:
    $supported_types = array('application/zip, application/x-compressed-zip');

    and even if I upload an actual ZIP file the error message still pops up.

    Here is a pastebin of my custom post type and meta box etc.

    I have tried to google the issue and tried to rephrase my questions the best way I can but I still have not found a solution :/

    It’s clear I am no professional so people might suggest I use a plug-in but I would actually like to use my functions.php file instead of the plug-ins…

    Could anyone please point me in the right direction?
    All help appreciated !

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi

    Please provide the error message you see after attempting to upload your zip.

    Also try
    $supported_types = array('application/zip,application/octet-stream');

    Thread Starter keysarrr

    (@keysarrr)

    @epicdevspace thanks for the response.
    I am receiving this error “The file type that you’ve uploaded is not a PDF.”
    Which should be changed to “ZIP”, I know but I feel like the error has something to do with this piece of code:

    function update_edit_form() {
        echo ' enctype="multipart/form-data"';
    } // end update_edit_form
    add_action('post_edit_form_tag', 'update_edit_form');

    Perhaps I’m wrong though…

    Moderator bcworkz

    (@bcworkz)

    I believe enctype=”multipart/form-data” is an appropriate attribute for the HTML <form> tag.

    The problem is whatever the file type in $arr_file_type['type'] is, it is not matching anything in the $supported_types array. You at least need to correct your array declaration like so:
    $supported_types = array('application/zip', 'application/x-compressed-zip',);
    You may need to add even more variants of ZIP file types to match any possible type in the submitted file. One example I found with a quick search suggested this:

    $supported_types = array(
       'application/zip',
       'application/x-zip-compressed',
       'multipart/x-zip',
       'application/x-compressed',
    );

    YMMV. If you still have trouble, try echoing out $uploaded_type right after it is assigned the file’s type. Upload a ZIP file as a test. Whatever that file type is needs to match one of the array elements (assuming the uploaded file is a legit ZIP file).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Upload zip files in custom meta box’ is closed to new replies.