Dynamically set the enctype for uploading files
<FM id= "Up" name= "Up" action= "upfileile.php" method= "post" enctype= "Multipart/fm-data" >
<input type= "File" Name= "upfileilefile[]"/>
<input type= "File" Name= "upfileilefile[]"/>
<button type= "Submit" >upfileile</button>
</fm>
The person who has studied JS may try to use JS to check and control enctype type
Fm=document.getelementbyid (' Up ');
if (Fm.getattribute (' enctype ')!= ' Multipart/fm-data ') {
Fm.setattribute (' enctype ', ' multipart/fm-data ');
The above code is completely in the format of the
FF run well but IE is not compatible, other browsers can not be compatible, IE cannot be compatible
To see the Yui class library to be inspired
In IE, FM has no ENCTYPE attribute, only encoding attribute, then the above code is rewritten as:
Fm=document.getelementbyid (' Up ');
if (Fm.getattribute (' enctype ')!= ' multipart/fm-data ' &&fm.encoding!= ' multipart/fm-data ')
if (fm.encoding) {
Fm.setattribute (' Encoding ', ' multipart/fm-data ');
}else{
Fm.setattribute (' enctype ', ' multipart/fm-data ');
}
}
The most external if judgment can be removed because you are going to set it to upload files so you can try this code.
<script type= "Text/javascript" >
function upfileile (FM) {
if (fm.encoding) {
Fm.setattribute (' Encoding ', ' multipart/fm-data ');
}else{
Fm.setattribute (' enctype ', ' multipart/fm-data ');
}
Fm.setattribute (' method ', post ');
if (!fm.getattribue (' action ')) {
Fm.setattribute (' action ', location.href);
}
Fm.submit ();
}
</script>
<FM action= "upfileile.php" onsubmit= "try{upfileile (this);} catch (e) {};return false; >
<input type= "File" Name= "upfileilefile[]"/>
<input type= "File" Name= "upfileilefile[]"/>
<button type= "Submit" >upfileile</button>
</fm>