Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open the file upload dialogue box onclick the image

I want to open the image upload file dialogue box if I click the button tag. Is it possible? If so how can I do it in PHP?

while{     echo "<td><button><img src='".$cfet['productimage']."' width='50' height='40'></button></td>"; } 
like image 949
user3386779 Avatar asked Mar 10 '14 05:03

user3386779


People also ask

How do I open file upload dialog box on image click?

And on the button's click event write the jQuery code like : $('#OpenImgUpload'). click(function(){ $('#imgupload'). trigger('click'); });


2 Answers

Include input type="file" element on your HTML page and on the click event of your button trigger the click event of input type file element using trigger function of jQuery

The code will look like:

<input type="file" id="imgupload" style="display:none"/>  <button id="OpenImgUpload">Image Upload</button> 

And on the button's click event write the jQuery code like :

$('#OpenImgUpload').click(function(){ $('#imgupload').trigger('click'); }); 

This will open File Upload Dialog box on your button click event..

like image 126
Abhay Prince Avatar answered Sep 22 '22 08:09

Abhay Prince


<input type="file" id="imgupload" style="display:none"/> <label for='imgupload'> <button id="OpenImgUpload">Image Upload</button></label> 

On click of for= attribute will automatically focus on "file input" and upload dialog box will open

like image 22
rajratna maitry Avatar answered Sep 19 '22 08:09

rajratna maitry