user5113770
user5113770

Reputation:

a condition for upload file only with specific format

How can I define a condition in a form input for uploading an image that user can just upload image with a specific format?

<div class="form-group">

    <div class="leftbox">
         <div class="col-sm-12" align="right">
              <input type="file" name="filedata" style="width:250px; background:none; " name="mipic"/>
                .jpeg,.jpg,.png
              </div>
         </div>
</div><br/>

Upvotes: 0

Views: 1580

Answers (2)

user5113770
user5113770

Reputation:

<input type="file" name="imagefilename" accept="image/x-png, image/gif, image/jpeg" />

Upvotes: 1

Jithesh_FC
Jithesh_FC

Reputation: 11

you can validate it by using the following JavaScript function.

function imageType() {
    var image = document.getElementById("Image").value;
    var extension;
    if (image == "") {
        alert("Upload a File With jpeg/jpg/png extension");
        return false;
    }
    else 
    {
        extension=image.split(".");
        if (extension[1] == "jpeg" ||extension[1] == "jpg" ||extension[1] == "png")
            return true;
        else {
            alert("File with " + image.split(".")[1] + " is not supported");
            return false;
        }
    }
    return true;
}

Upvotes: 0

Related Questions