[英]using isset($_POST['upload']){ … } and calling it on form input type file change and not the submit button
In my php page, I have a form as: 在我的php页面中,我的表单为:
<form enctype = 'multipart/form-data' method="post">
Select File:
<br/>
<input type="file" name="file" />
<input type="submit" name="upload" value="Upload" />
</form>
When I submit the form on clicking the submit 'upload', the following php is called which is on the same php page: 当我单击“提交”按钮提交表单时,将调用以下php,它位于同一php页面上:
<?php
if (isset($_POST['upload'])) { ...Do stuff... }
?>
Now, I dont want to use the submit in my html form and want to trigger this php whenever a file in the input type file is selected. 现在,我不想在我的html表单中使用Submit,并且无论何时在输入类型文件中选择一个文件都想触发此php。 ie the form should be submitted automatically on file selection without the submit button. 即,表单应在选择文件时自动提交,且不带“提交”按钮。 Also, i want a if condition such as isset($_POST['']) and dont want to use just a post check as $_SERVER['REQUEST_METHOD'] == 'POST' 另外,我想要一个if条件,例如isset($ _ POST ['']),并且不希望仅使用$ _SERVER ['REQUEST_METHOD'] =='POST'
Any help will be appreciated. 任何帮助将不胜感激。
All you have to set an event handle for change in input file 您只需设置事件句柄即可更改输入文件
<script type="text/javascript">
$(function() {
$("input:file").change(function (){
$('form').submit();
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.