When a single form
The code is as follows |
|
<form action= "?" method= "Post" enctype= ' Multipart/form-data ' > File Upload: <input type= "file" name= "file" id= "file"/> <input type= "Submit" id= "send" value= "submitted"/> </form>
<?php Determine if the pic file box has selected a file if (!empty ($_files[' file '] [' tmp_name '])) { Echo ' selected file '; }else { echo ' Please select file '; } Ps:$_files behind the [' tmp_name '] must not forget to write, it means to be a temporary meaning ?>
|
Of course this can be used to determine the first JS, the following methods:
The code is as follows |
|
<script> var Send=document.getelementbyid ("send"); Send.onclick=function () { var File=document.getelementbyid ("File"). Value; if (file.length<1) { Alert (' Please select Picture '); return false; } } </script> |
Multi-File Upload <input type= "file" Name= "UploadFile" contenteditable= "false" style= "width:80%" >
There are multiple forms in the form,
When submitting a form you need to determine that at least one input has been selected for the file.
The code is as follows |
|
<input type= "File" Name= "UploadFile" contenteditable= "false" style= "width:80%" ><br> <input type= "File" Name= "UploadFile" contenteditable= "false" style= "width:80%" ><br> <input type= "File" Name= "UploadFile" contenteditable= "false" style= "width:80%" ><br> <input type= "File" Name= "UploadFile" contenteditable= "false" style= "width:80%" ><br> <input type= "File" Name= "UploadFile" contenteditable= "false" style= "width:80%" > |
Use jquery for judgment:
The code is as follows |
|
var fileflag = false; $ ("Input[name= ' UploadFile ']"). each (function () { if ($ (this). Val ()!= "") { Fileflag = true; return false; } }); if (Fileflag) { Alert ("already has a choice of good documents"); } |
As long as Fileflag is true, you can exit each loop without having to judge the rest of the input.
Use return False to exit the loop in each, using return true to end the current secondary loop for the next loop.