简体   繁体   中英

Issue with file upload in one click

I'm using an icon instead of the regular upload input + submit button. I want the upload to starts automatically right after a file is chosen. Once the user selects a file, nothing happens though.

<form action="upload.php" method="POST" enctype="multipart/form-data">
  <input id="upload"  type="file" name="image"  style="display:none" value=/>
  <input name="wishid" type="hidden" value=/>
  <img id="upload_img" src="/images/upload.png">
</form>


<script type="text/javascript">
  $('#upload_img').click(function(){
  $('#upload').click();
 });
</script>

What do I need to add to the jQuery code to actually start the upload process via upload.php ?

Take a look at this description of how to replace input:file with image and then you can just use the code below...

<script type="text/javascript">
  $('#upload_img').click(function(){
    $('form').submit();
 });
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM