简体   繁体   English

使用isset($ _ POST ['upload']){…}并在表单输入类型文件更改而非提交按钮上调用它

[英]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.

相关问题 jQuery提交表单输入类型“文件”更改的表单 - Jquery submit form on form input type 'file' change 使用html5 / ajax / javascript上传/发布文件,而不使用表单和<input type=file> - upload / POST file with html5 / ajax / javascript without using form and <input type=file> php isset($_post[]) 和 javascript form.submit - php isset($_post[]) and javascript form.submit 在调用 jquery form.submit 时,需要澄清类型按钮输入与提交类型输入之间的区别 - Clarification wanted in the difference between input of type button vs input of type submit when calling jquery form.submit RoR:在提交表单按钮上上传jquery文件 - RoR: jquery file upload on submit form button 不使用提交按钮发送输入类型文件 - Send input type file without using submit button 在文件输入更改时,将带有 formdata 的表单提交到 php 文件并上传图像文件 - On file input change submit form with formdata to php file and upload image file 表单提交后输入按钮更改颜色 - Input button change color after form submit 使用什么而不是if(isset($ _ POST [&#39;submit&#39;]))for this.form.submit()? - What to use instead of if(isset($_POST['submit'])) for this.form.submit()? 如何在相同的提交类型输入字段(按钮)中使用onclick(js函数)方法提交表单和处理事件 - How to submit form and handle events using onclick(js function) method in same submit type input field(button)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM