-1

Is there a way to upload a file without using an <input type="file"> I want the user to upload their file when clicking on a photo Based on JavaScript

ThisClark
  • 14,352
  • 10
  • 69
  • 100
sifo ou
  • 1
  • 3
  • 1
    to specify a file location or to show a file choose dialog box, you depend on the browser's inbuilt code, so the technical answer is NO, but you can hide `input` tag and trigger the click dynamically – Dickens A S Mar 29 '20 at 02:49

1 Answers1

0

I believe you will need the input but you can hide it with CSS so the user is not forced to interact with it, then you provide functionality of the input through javascript click event on an image.

Basically, this is the technique, already answered here but adapted for an image:
https://stackoverflow.com/a/12436476/1161948

$("#select_logo").click(function(e){
   e.preventDefault();
   $("#logo").trigger('click');
});
#logo { display: none; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>Click the image to upload</div>
<img src="https://placehold.it/150x50" id="select_logo"><input type="file" id="logo">

Then, depending on what type of file you are expecting uploaded, you will need to do more work to read the contents of the file. Here's an example: https://stackoverflow.com/a/44161989/1161948

ThisClark
  • 14,352
  • 10
  • 69
  • 100