Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uploading a pic from computer with single button in php

<html>
   <head>
      <title>File Upload Form</title>
   </head>
   <body>
      This form allows you to upload a file to the server.<br />
      <form action="getfile.php" method="post"><br />
         Type (or select) Filename: 
         <input type="file" name="uploadFile" />
         <input type="submit" value="Upload File" />
      </form>
   </body>
</html>

I am working on a php language . I am uploading a pic from my computer . But there are two buttons ie choose file and Upload file . CHOOSE FILE is used to select the picture from PC and upload file button is used as SUBMIT button but i need a single button by clicking on it it will open my pc window to browse the photos and select it and it also act as a submit button . Is there any way to do this with single button

like image 753
PHP_USER1 Avatar asked Dec 01 '25 08:12

PHP_USER1


2 Answers

you need to change to things in your form tag:

1) Add a name tag: say name="frm"
2) enctype="multipart/form-data"

Then in your input file type add a function onchange="frm.submit();" // Where frm is name of the form 
like image 73
Mayank Sharma Avatar answered Dec 02 '25 22:12

Mayank Sharma


You can wait an event change on the input type="file" and send file after this event.

If you use jQuery, you can send the form with .submit().

Try with something like this

$("input[type='file']").on("change", function(){
   $("form").submit();
});

.on("change", handler) : http://api.jquery.com/change/

.submit() : http://api.jquery.com/submit/

like image 37
Donovan Charpin Avatar answered Dec 02 '25 23:12

Donovan Charpin