php - How to get image type -
how can getting image type in ajax allow png , jpg before sending data?
$(document).ready(function() { $("#sharepostbtnx2").click(function(){ //--here can add together ajax code allow png , jpg images only-- var formdata = new formdata($("#postform")[0]); $.ajax({ url: "postingthepost.php", type: 'post', data: formdata, async: false, success: function (response) { $(response).hide().prependto("#responds").fadein(); }, cache: false, contenttype: false, processdata: false }); homecoming false; });
<input type="file" accept="image/*" id="snap" name="snap" multiple="no" title="choose image file upload" />
in javascript
var input = $('#snap')[0]; if (input.files && input.files[0]) { var ofile = input.files[0]; var ofile = ofile.size; var ofiletype = ofile.type //option 1 // check image type (jpg , png allowed) var rfilter = /^(image\/jpeg|image\/png)$/i; if (! rfilter.test(ofiletype)) { alert('please select valid image file (jpg , png allowed)'); return; } //option 2 if (!ofile.filename.match(/\.(jpg|jpeg|png|gif)$/)){ //todo validation image type process ajax } }
tutorial link javascript api doc
php jquery ajax
No comments:
Post a Comment