これは html から
<form action="http://localhost/own/import.php" method="post" enctype="multipart/form-data" name="form1">
<input type="file" name="xmlfile" id="file1">
<input type="file" name="uploaded_image" id="file2">
<input type="submit" id="submit" name="Submit" value="Submit" style="margin:0 0 0 150px;">
これはJavaスクリプトファイルです
function getExt(filename) {
var dot_pos = filename.lastIndexOf(".");
if (dot_pos == -1) {
return "";
}
return filename.substr(dot_pos + 1).toLowerCase();
}
function validate_ext() {
var filename = document.getElementById("file1").value;
var filename2 = document.getElementById("file2").value;
var ext = getExt(filename);
var ext2 = getExt(filename2);
if (filename != "") {
if (!(ext == "xml")) {
alert("Please upload XML file format only");
return false;
}
}
if (filename2 != "") {
if (!((ext2 == "jpg") || (ext2 == "jpeg") || (ext2 == "png"))) {
alert("Please upload jpg, jpeg, png file format only");
return false;
}
}
return true;
}
$(document).ready(function() {
$('#submit').click(validate_ext);
alert("test");
});
私もここでコードを共有していますhttp://jsfiddle.net/vikastyagi87/XugLp/18/
</p>