Restrict upload by filetype or mimetype using Dexterity on Plone

痴心易碎 提交于 2019-12-05 15:52:07
David Bain

I've decided to use javascript for my first line of validation. I've based my solution on information found at <input type="file"> limit selectable files by extensions

Based on the advice my script looks something like this:

$(document).ready( function() {

function checkFile(event) {
        var fileElement = document.getElementById("form-widgets-audio_file-input");
        var fileExtension = "";
        if (fileElement.value.lastIndexOf(".") > 0) {
            fileExtension = fileElement.value.substring(fileElement.value.lastIndexOf(".") + 1, fileElement.value.length);
        }
        if (fileExtension == "mp3") {
            return true;
        }
        else {
            alert("You must select a mp3 file for upload");
            return false;
        }
    }

$("form#form").bind("submit",checkFile);

});

This is half the solution, next I'll need to add validation on the server side.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!